Polymer 通知更改列表中的对象属性
我有一个名为accounts的对象列表,这些对象绑定到vaadin数据网格。我还有一个逻辑,用一个大的交易列表更新每个帐户的余额属性Polymer 通知更改列表中的对象属性,polymer,polymer-1.0,Polymer,Polymer 1.0,我有一个名为accounts的对象列表,这些对象绑定到vaadin数据网格。我还有一个逻辑,用一个大的交易列表更新每个帐户的余额属性 _updateAccountBalance: function() { this.accounts.map(account => { account.balance = 0; }); this.transactions.map(trans => { trans.account.balance += trans.amount; });
_updateAccountBalance: function() {
this.accounts.map(account => { account.balance = 0; });
this.transactions.map(trans => { trans.account.balance += trans.amount; });
// This doesn't notify other watchers of the accounts
//this.set("accounts", this.accounts);
// hack to get notifications to work
this.accounts.map((account, idx) => {
this.set("accounts." + idx + ".balance", account.balance);
});
}
我的问题是:有没有更惯用的方法
因为有很多事务,在累加器映射中使用set会生成很多通知。尝试使用从map函数返回的数组
var accounts = [{balance: 23}, {balance: 3}, {balance: 2}]
var newAccounts = accounts.map(account => {
account.balance = 0;
return account;
});
this.set("accounts", newAccounts);
这似乎奏效了。它有效地克隆了阵列。我试着研究如何使用NOTIFY的基本调用,但它看起来相当复杂。