我正在从集合中的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();
},
答案 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将根据响应创建一个模型。