2014-02-12 60 views
0

當我正在偵聽集合中模型的布爾屬性的更改事件時,如何處理該事件以在集合中的所有其他模型上關閉布爾。骨幹集合布爾型翻轉

+0

你嘗試過什麼?你在聽什麼活動?粘貼一些代碼,以便我們可以幫助你。 – Puigcerber

回答

0

試試這個:

// in your model 
yourModel.on('change:yourBooleanAttribute', yourCollection.setAllButCurrent); 

// and in your collection 
setAllButCurrent: function(changedModel, value, options) { 
    // here you can iterate through `this.models` and for each model 
    // if it's `id` differ from changedModel id, change it's `yourBooleanAttribute` 
    // to the opposite value of `value` 
} 
+0

這就是我最終做的,但不是我最初想做的。我希望打破模型/集合/模型範例。我覺得頂級模型有點多餘。該集合應該足夠聰明,可以處理這些類型的更改。 – Caranicas