通知更改列表中的对象 属性
Notify change to object property in list
我有一个名为帐户的对象列表,这些对象绑定到 vaadin 数据网格。我也有逻辑更新每个帐户的余额 属性,其中包含大量交易。
_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);
});
}
我的问题是:有没有更惯用的方法来做到这一点?
因为事务比较多,在accumulator map中使用set会产生很多通知。
尝试使用从 map 函数返回的数组。
var accounts = [{balance: 23}, {balance: 3}, {balance: 2}]
var newAccounts = accounts.map(account => {
account.balance = 0;
return account;
});
this.set("accounts", newAccounts);
我有一个名为帐户的对象列表,这些对象绑定到 vaadin 数据网格。我也有逻辑更新每个帐户的余额 属性,其中包含大量交易。
_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);
});
}
我的问题是:有没有更惯用的方法来做到这一点?
因为事务比较多,在accumulator map中使用set会产生很多通知。
尝试使用从 map 函数返回的数组。
var accounts = [{balance: 23}, {balance: 3}, {balance: 2}]
var newAccounts = accounts.map(account => {
account.balance = 0;
return account;
});
this.set("accounts", newAccounts);