次のバックボーン構造があります。
- collection[order_items]
- collection[menu_items]
- price
- quantity
数量属性の変更をリッスンしたいので、それを機能させました
var CheckoutView = Backbone.Marionette.ItemView.extend({
template: '#template-checkout',
initialize: function (options) {
this.order_collection = options.collection;
_(this.order_collection.models).each(function (element, index, list) {
this.listenTo(element.get("menu_items"), "change:quantity", this.onOrderItemsChanged);
}, this);
},
onOrderItemsChanged: function (model, val, options) {
console.log(model.get("name"));
}
});
しかし、マリオネットまたはバックボーンには、親コレクションをループして各子コレクションにリスナーを追加する代わりに、それを行うためのより良い方法がありますか?
this.listenTo(this.order_collection, "change:menu_items:quantity", this.on OrderItemsChanged)
(私にはうまくいきませんでした)