this.model.collection.where({selected: true})
モデルの配列を返します
selected
次に、返されたモデルの属性を false に設定したいと思います。
これどうやってするの?
@model.collection.where({selected: true})
(コーヒースクリプト)
this.model.collection.where({selected: true})
モデルの配列を返します
selected
次に、返されたモデルの属性を false に設定したいと思います。
これどうやってするの?
@model.collection.where({selected: true})
(コーヒースクリプト)
これを行うことができます.each
_.each(this.model.collection.where({selected: true}), function(m){
m.set('selected', false);
});
where
一致するオブジェクトの配列を返すため、その配列をアンダースコアの最初の引数に渡す必要がありますeach
。
次の方法でもこれを行うことができますmap
。
this.model.collection.map(function(m){if(m.get('selected'){m.set('selected', false);}});
map
コレクション (または配列) 内のすべての要素を取得し、それらにメソッドを適用するので。
単純なループの何が問題になっていますか?
m.set('selected', false) for m in @model.collection.where(selected: true)
あるいは:
for m in @model.collection.where(selected: true)
m.set('selected', false)
アンダースコアは便利ですが、すべてに使用する必要があるという意味ではありません。
this.model.collection.where({selected: true}).each(function(model){
model.set({selected:false});
}