1
私は "物"の配列を含むコントローラを持っています。これらのそれぞれの中には、「副交渉」の配列があります。私は、すべての事柄(下位の平らな配列)のすべての下位条件を含む計算されたプロパティを作成したいと思います。@eachを使って配列内の配列を見ることはできますか?
私の計算されたプロパティは[email protected]
に依存します。私がをに設定した場合、物のプロパティがsubthings
になります。計算されたプロパティが更新されています。しかしpushObjects
という新しいデータをという既存のsubthings
という配列に追加すると、計算されたプロパティは更新されません。
説明するためにjsfiddleを作成しました。コードは以下の通りである:
App = Em.Application.create({});
App.controller = Em.Object.create({
things: [
Em.Object.create({subthings:[]}),
Em.Object.create({subthings:[]}),
Em.Object.create({subthings:[]})
],
allSubThings : function() {
var things = this.get('things');
var results = [];
things.forEach(function(thing) {
results.pushObjects(thing.get('subthings'));
});
return results;
}.property('[email protected]').cacheable()
});
setTimeout(function() {
var things = App.controller.get('things');
// This works:
things.objectAt(0).set('subthings',[1,2,3]);
}, 1000);
setTimeout(function() {
var things = App.controller.get('things');
// This does not:
things.objectAt(1).get('subthings').pushObjects([1,2,3]);
}, 2000);
ありがとう!
のおかげで、別の
@each
を追加します!たぶん私はここで何をしているのかよく分かりません。あなたの解決策は、subthings配列自体の長さではなく、 "subthings"配列の各要素のlengthプロパティを観察しているようです。 – rharperEmberのドキュメントより:http://emberjs.com/guides/object-model/computed-properties-and-aggregate-data/ "@eachは1つのレベルしか動作しないことに注意してください。todosのようなネストされたフォームは使用できません。 .owner.nameまたはtodos。@ each.owner。@ each.name –