このコードが機能しない理由がわかりません。ドキュメントを
読んで
、を呼び出す必要があります。 templateHelpers
私の目標は、this.collection.length
をテンプレートに渡すことです。
ヒントはありますか?ありがとう。
Backbone.Marionette v0.9.5 を使用しています
return Marionette.CompositeView.extend({
className: 'user-board',
template: usersTemplate,
itemView: userItemView,
initialize: function () {
this.collection = new UseList();
this.collection.fetch();
},
appendHtml: function (collectionView, itemView) {
collectionView.$el.find('ul.users-list').append(itemView.el);
},
templateHelpers: function () {
console.log(this.collection.length);
},
serializeData: function () {
return {
weekly: this.options.weekly,
users_length: this.collection.length // here the length is zero
// after the fetch the length is > 0
// but in template remains 0
};
}
});
私の問題を解決するには、次のことを行う必要があります...
initialize: function () {
_.bindAll(this, 'render');
this.collection = new NewCollection();
this.collection.fetch({
success: this.render
});
}
それを機能させるためのより良い方法はありますか?