[英]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.