Backbone.js 在主干上获取isn';无法填充我的模板
我在我的集合中做了一个fetch,我做了一个console.log(),它正在工作,但是当我设置为模板时,没有显示值 我认为:Backbone.js 在主干上获取isn';无法填充我的模板,backbone.js,Backbone.js,我在我的集合中做了一个fetch,我做了一个console.log(),它正在工作,但是当我设置为模板时,没有显示值 我认为: var reposCollection = new Sice.Collections.RepositoryList(); reposCollection.fetch(); this.$el.html(this.template({collection: reposCollection.models})); 我的模板是:
var reposCollection = new Sice.Collections.RepositoryList();
reposCollection.fetch();
this.$el.html(this.template({collection: reposCollection.models}));
我的模板是:
<% _.each(collection, function(repos) { %>
<tr>
<td><%= repos.attributes.name %></td>
<td><%= repos.attributes.description %></td>
<td><%= repos.attributes.language %></td>
</tr>
<% }); %>
我不知道发生了什么事 模板在
获取完成之前呈现。您需要在fetch
的success
回调中调用呈现代码:
var reposCollection = new Sice.Collections.RepositoryList();
reposCollection.fetch({
success: (collection, response, options) => {
this.$el.html(this.template({collection: collection.models}));
}
});