聚合物.动态添加或删除观察者的方法 [英] Polymer. Way to dynamically add or remove observer
本文介绍了聚合物.动态添加或删除观察者的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法可以在元素初始化时添加或删除观察者? 我可以这样定义观察者:
Is there a way to add or remove observer not in the moment of element initing? I can define observer this way:
observers: ['dataChanged(data.*)']
我可以稍后删除此观察者,还是可以设置与该观察者不同的方式?
Can i remove this observer later or can I set this observer different way than that?
推荐答案
您可以通过以下方式轻松地动态添加观察者:
You can easily add an observer dynamically, either by:
this._addObserverEffect("property", observerFunction);
或
this._addComplexObserverEffect("dataChanged(data.*)");
拆卸比较困难,Polymer没有提供执行此操作的功能.尽管您可以在_propertyEffects
数组中搜索它,但我不建议这样做.也许只需检查您的观察者功能是否仍应处于活动状态,然后返回即可.
Removing is harder and Polymer does not provide a function to do this. Although you could search for it in the _propertyEffects
array, I wouldn't recommend it. Maybe just check in your observer function whether it should still be active, and return if not.
这篇关于聚合物.动态添加或删除观察者的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文