gpt4 book ai didi

javascript - Polymer 1.X - 复杂的观察者不开火

转载 作者:行者123 更新时间:2023-11-30 14:40:53 24 4
gpt4 key购买 nike

我对所有对象的子属性都有一个复杂的观察者,但它从未触发,我不明白为什么..

//Declaration's property
requirement: {
type:Object,
value: {
allLoaded: false,
tagsLoaded: false
}
},

//Complex observer
observers: [
'requirementChanged(requirement.*)'
],

//Observer definition
requirementChanged: function(val){
console.log('obs : ', this.requirement, val);//Just to see what's in there
},

//The action that should trigger the observer
if(res.length > 0)
{
this.sharedInfo.assetTags = res;
this.set('requirement.tagsLoaded', true);
this.notifyPath('requirement.tagsLoaded');
}

谢谢大家,祝你有个愉快的一天

最佳答案

您的属性声明的设置方式使其有效非通知
您必须在 Polymer 的属性声明上设置 notify 以传播可观察到的更改触发器。
来自 Polymer 1.x 文档 -

notify - A notifying property supports upward data flow. By default, properties are non-notifying, and don't support upward data flow.

尝试将属性声明更改为 -

//Declaration's property
requirement: {
type:Object,
value: {
allLoaded: false,
tagsLoaded: false
},
notify: true
}

这里是进一步阅读 Observable and Unobservable changes

关于javascript - Polymer 1.X - 复杂的观察者不开火,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49673691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com