0
对于我的布局我有一个组件需要在渲染完成后初始化,然后再次如果我的数据中有任何更改。如何确定我的ractive计算值是否已更改
这将工作的很好,但我依靠计算值为每个客户端筛选和更改输出,并通过observe
更改事件经常触发。我做什么:
let myRactive = new Ractive({
el: '#clientContainer',
template: myTemplate,
magic: true,
modifyArrays: true,
data: {data}, //=> this is an awful lot of Data changing all the Time
computed: {
usefulData(){
let tempdata = this.get('data');
//=> a lot of rearranging, filtering and sorting
// to adapt the data only for this specific client
return tempdata;
}
onrender: function() {
initmyLayoutComponent()
}
});
于是,我就让它这样
myRactive .observe('usefulData', function (newValue, oldValue, keypath)
destroymyLayoutComponent();
initmyLayoutComponent();
});
但这发射的)每次什么在data
变化(即使是一些完全无关的usefulData
) ,和b)在ractive提交DOM之前,组件被重新初始化为提前。
有没有一种方法可以只观察计算出来的值,或者哪一种会更好 - 只是观察计算值中的特定动作(如我想对添加/删除的对象作出反应,但不反应更改的值)?
非常感谢。我会尝试这种方法,并尝试调整我的原始脚本。 – Torf