我有一个集合,我知道它正在获取整个集合,但是如何访问从 fetch 返回的数据?
/js/views/idea.js
define([
'jquery',
'underscore',
'backbone',
'collections/ideas'
], function($, _, Backbone, IdeasCollection) {
var IdeasView = Backbone.View.extend({
el: $('#container'),
render: function(){
this.collection = new IdeasCollection();
console.log( this.collection.fetch() ); // I can see data
var data = {};
var template = _.template( $('#ideasView').html(), data);
$('body').removeClass().addClass('blog');
this.$el.html( template );
}
});
return IdeasView;
});
/js/collections/ideas.js(为简洁起见。)
var IdeasCollection = Backbone.Collection.extend({
url: '/api/ideas',
model: IdeaModel
});