问题描述
所以我正在尝试将这些观察者方法动态添加到 Ember.js 对象中
So i am trying to dynamically add these observer methods to a Ember.js object
到目前为止我有这段代码,但是 item.methodToCall 函数没有被调用
I have this code so far but the item.methodToCall function is not getting called
谁能告诉我我做错了什么?有一个更好的方法吗 ?我应该在 mixin 中这样做吗?如果有请
Can anyone tell me what i am doing wrong ? Is there a better way to do this ? Should i be doing this in a mixin ? If so please
推荐答案
我不知道你的具体用例,但正如你所说,你描述的问题可以用 Mixin 解决,见 http://jsfiddle.net/pangratz666/a3Usx/
I don't know your exact use case, but as you said, your described problem could be solved with a Mixin, see http://jsfiddle.net/pangratz666/a3Usx/
JavaScript:
示例用例:
<小时>
另一种实现是使用数组 watchProperties
的 mixin,该数组是应观察的属性列表,请参阅 http://jsfiddle.net/pangratz666/bSF3Z/:
Another implementation would be a mixin which uses an array watchProperties
, which is a list of properties which shall be observed, see http://jsfiddle.net/pangratz666/bSF3Z/:
JavaScript:
这篇关于如何将观察者方法动态添加到 Ember.js 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!