附录一有一个模型<编码>Stock,该模型有多个<编码>Stock Partition(其名称为partitions
,其名称为Array)。
The Stock
model has a property usedAmount
that should change when any of all partition.amount
changes, and, of course, be updated when a partition is added/removed.
Example :
stock.get( usedAmount ) -> 0
stock.get( partitions ) -> [Class, Class, Class]
stock.get( partitions )[0].set( amount , 12)
stock.get( usedAmount ) -> I want here to return 12
stock.get( partitions )[1].set( amount , 12)
stock.get( usedAmount ) -> I want here 24
How could Stock
observes each partitions.amount
?
I can write a function addPartition
that looks like this :
addPartition: function(partition) {
partition.addObserver( amount , function() {
this.get( owner ).notifyPropertyChange( usedAmount );
});
}
但我希望有一个更好的解决办法。