0

我正在从集合中的 instagram url 读取 json 数据,并在视图中获取集合数据,但没有得到任何响应。怎么了?

模型:

        define([
          'underscore',
          'backbone'
        ], function(_, Backbone) {var TopListModel = Backbone.Model.extend(return TopListModel;});

收藏:

define([
  'jquery',
  'underscore',
  'backbone',
  'models/topList/topListModel'
], function($, _, Backbone, TopListModel){
  var TopListCollection = Backbone.Collection.extend({
  model: TopListModel,
  url: 'https://api.instagram.com/v1/tags/'+hashtag+'/media/recentaccess_token='+access_code,
  });

 return TopListCollection;
});

看法:

define([
  'jquery',
  'underscore',
  'backbone',
  'text!templates/sidebar/topList.html',
  'collections/topList/TopListCollection',
  //'text!templates/home/homeTemplate.html'
], function($, _, Backbone, topList, TopListCollection){

  var TopListView = Backbone.View.extend({
    el: $("#sidebar"),
    initialize: function(){
      _.bindAll(this, 'render');

      var topListCollection = new TopListCollection();
      topListCollection.fetch({success: function(collection, data){            
        console.log(data);
      }});
      //this.render();
    },
4

1 回答 1

0
define([
      'underscore',
      'backbone'
    ], function(_, Backbone) {var TopListModel = Backbone.Model.extend(return TopListModel;});

应该是:

define([
      'underscore',
      'backbone'
    ], function(_, Backbone) {var TopListModel = Backbone.Model; return TopListModel;});

更好的是,除非您在模型中做一些特殊的事情,否则您不需要实际定义它。Backbone 将根据响应创建一个模型。

于 2013-01-09T14:16:58.043 回答