Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8379973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:20:02+00:00 2026-06-09T16:20:02+00:00

We are loading the JSON from the file using backbone collection.. Now if i

  • 0

We are loading the JSON from the file using backbone collection.. Now if i take the same content of the file and put that into an array and call a url function, nothing seems to work.. Can you please help..

var cool = {};
cool.Item = Backbone.Model.extend({});
cool.Items = Backbone.Collection.extend({
        model: cool.Item,
                url: "data.json"

This code works

var cool = {};
cool.Item = Backbone.Model.extend({});
cool.Items = Backbone.Collection.extend({
        model: cool.Item,
                url: this.return(cool_cont());

function cool_cont()
{
* JSON object*
} 

This code doesnt work..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:20:04+00:00Added an answer on June 9, 2026 at 4:20 pm

    Your logic in this has some fallacies. The example that works here is that you define the url-attribute as data.json. What happens when you fetch, is that Backbone makes an ajax -request for that url (stumbling upon your file) and gets returned the content there (your json data).

    Now your second try is where everything goes wrong. First of all:

    url: this.return(cool_cont());
    

    I don’t know what this does (or more likely does not do) and I don’t want to know. The basic premise of the url-attribute/function is that it is meant to

    Set the url property (or function) on a collection to reference its location on the server.

    -Quote from the Backbone.js docs (true story)

    So what you do here is that you pass the data you want to populate your collection with as the reference to its location on the server (frankly I think that you’re not even doing that), which is plain wrong.

    So url == the path_to_your_data_be_it_url_or_file

    url can either be a string (aka a static path) or a function (for example creates the path using some attributes of the model as parts of it).

    If you want to insert some faux data to your Collection and you don’t want to do it with an external file, do it like this:

    var json_data = [
      {"foo": "bar"}, // model 1
      {"foo": "bar2"}, // model 2
      ...
      {"foo": "barN"}, // model N
    ];
    
    var options = {...}; // optional
    
    var myCollection = new MyCollection(json_data, options);
    

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I push items returned from this json file into an array called
I m using tableview to populate an array from json file...In my view Controller
I am loading html into a UIWebView from iOS local file system. That HTML
I am having trouble with loading JSON into an app that im creating $(#load_basic).click(function(){
I'm loading Json into an NSDictionary and the output is below. I'm just not
I'm loading JSON data (array of objects) via service, onReady, and want to display
I'm loading a JSON string in Django using simplejson , thus: obj = json.loads('{name:
In my application, I am loading JSON data using the NSURLConnection method, what looks
[revised] I'm creating a TreePanel in ExtJs that is loading its children from a
I have a JSON file and i have to read data from this file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.