收集没有收到来自Instagram网址的任何回复

时间:2013-01-09 08:48:22

标签: javascript backbone.js requirejs instagram

我正在从集合中的instagram网址读取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();
    },

1 个答案:

答案 0 :(得分: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将根据响应创建一个模型。