[英]Ractive.js Pattern Indirect Observer Reports Same Value
我使用Ractive.js綁定javascript對象和HTML表單。 我的對象看起來像這樣:
entity: {
id: 'some id'
type: 'a type'
names: [
{
locale: 'en',
name: 'some name'
},
{
locale: 'tr',
name: 'some translation'
}
]
}
我想訂閱名稱更新。 我通過以下方式注冊更新:
ractive.observe({
// indirect observer
'entity': function(newValue, oldValue, key) {
console.log(key + ' is changed from ' + oldValue + ' to ' + newValue);
},
// direct observer
'entity.names.*': function(newValue, oldValue, key, index) {
console.log(key + ' is changed from ' + oldValue + ' to ' + newValue + ' and index is ' + index);
}
}
但是,上述兩個觀察者的oldValue
和newValue
始終相同(等於觀察到的模式的最新值)。
根據直接觀察者的文檔,此行為是預期的。 但是,間接觀察者應提供不同的值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.