我想知道如何告诉骨干等到我的集合已经获取模型,然后呈现下划线位。骨干视图:等到收集提取
在控制台返回从一个字段缺少下划线模板错误。当我CONSOLE.LOG(this.collection.toJSON()),它不显示任何数据。所以我认为,该视图是在数据被提取之前呈现的。我如何告诉视图等待它被提取?
///////查看////////
define([
'jquery',
'underscore',
'backbone',
'collections/mitarbeiter',
'text!/aquilamus/templates/mitarbeiter/mitarbeiter.html'
], function($, _, Backbone, MitarbeiterCollection, MitarbeiterTemplate){
var MitarbeiterListView = Backbone.View.extend({
el: $("#container"),
initialize: function(){
this.collection = new MitarbeiterCollection;
this.collection.fetch();
var newtemplate = MitarbeiterTemplate;
this.template = _.template($(newtemplate).html());
},
render: function(){
var renderedContent = this.template(this.collection.toJSON());
$(this.el).html(renderedContent);
return this;
}
});
// Our module now returns our view
return MitarbeiterListView;
});
如果你的jQuery包括,如果你问我,你使用承诺的解决方案是最好的选择。但是,如果你不使用jQuery然后结合“复位”事件是要走的路。 – fiskers7 2013-03-22 17:57:45
THX了很多的帮助!它完美地完成了这项工作! – Tino 2013-03-23 11:12:59
只是想知道为什么'var self = this'?我们不能只是'_.bind(函数,这个)'? – 2015-09-22 15:07:55