骨干收集和Backbone模型事件

时间:2013-02-09 09:46:25

标签: javascript backbone.js

我有两个观看我的收藏中的不同事件。

this.cartCollection.on('quantityAdded', this.QuantityAdded, this);          
this.cartCollection.on('quantitySubtracted', this.QuantitySubtracted, this);
this.cartCollection.on('salesPriceRateUpdated', this.UpdateCartItemPrice, this);
this.cartCollection.on('unitMeasureUpdated', this.ChangeItemPriceOnUnitMeasure, this);
this.cartCollection.on('warehouseCodeUpdated',this.ChangeItemPriceOnWarehouseCode,this)
this.cartCollection.on('quantityOrderedUpdated', this.UpdateCartItem, this);
this.cartCollection.on('quantityDefectiveUpdated', this.UpdateCartItem, this);
this.cartCollection.on('discountUpdated', this.UpdateCartItem, this);       
this.cartCollection.on('discountAppliedToAll', this.ApplyDiscountToAll, this);

this.cartCollection.on('clearedTransaction', this.VoidTransactionWithValidation, this)

on maintemplate.js我有这个

this.collection.bind("add", this.ModelAdded, this);         
this.collection.bind("change", this.ModelChanged, this);
this.collection.bind("viewDetails", this.ShowItemDetails, this);
this.collection.bind("viewFreeStock", this.ShowFreeStock, this);
this.collection.bind("viewAccessory", this.ShowAccessory, this);
this.collection.bind("viewSubstitute", this.ShowSubstitute, this);
this.collection.bind("itemRemoved", this.RemoveItem, this);
this.collection.bind("reset", this.ReinitializeCart, this);

但在我的模板上,这些事件来自我的模型,该模型链接到我的收藏。触发this.cartCollection.on('salesPriceRateUpdated', this.UpdateCartItemPrice, this);

我正在按this.cartCollection.reset更新集合,然后在我触发this.cartCollection.add(data) this.UpdateCartItemPrice'后不再捕获任何事件时传递更新的模型salesPriceRateUpdated maintemplate。我甚至尝试添加{merge:true}但结果相同。

有关如何正确保存事件绑定的任何想法?感谢

0 个答案:

没有答案