weixin_33711647 2014-04-24 10:35 采纳率: 0%
浏览 16

将JSON载入骨干模型

I am trying to load a json file into a backbone model like so :

var Feed = Backbone.Model.extend();

var FeedCollection = Backbone.Collection.extend({
    model: Feed,
    url:'feed.json'


var feeds = new FeedCollection();

feeds.fetch({success : function() {
       console.log(feeds);
}})

The first log returns the JSON obect within the file, just returns an object without the json data.

  • 写回答

2条回答 默认 最新

  • weixin_33696106 2014-04-24 10:45
    关注

    You should try and mention a few more properties for your fetch call. Try passing in the method argument and the dataType argument. If you are getting JSONP, try passing in callback too. Here is a code snippet I use that should help you out -

    feeds.fetch({
        method:"GET",
        dataType: 'jsonp',
        jsonp: 'callback'
    }).complete(function(resp) {
        // Do stuff here
    });
    
    评论

报告相同问题?