我正在尝试创建一个行为,将计算属性添加到它增加的元素中。
示例模板:
<template>
<span>[[getLight(0)]]</span><br />
<span>[[getLight(1)]]</span><br />
<span>[[getLight(2)]]</span><br />
</template>
<script>
Polymer({
is: 'vertical-light',
behaviors: [
stopLightBehavior
]
});
</script>
示例行为:
//Located in another file, with its implementation obscured
stopLightBehavior = {
ready: function() {
this._myArray = [true, false, false];
setInterval(function() {
this.unshift('_myArray', this.pop('_myArray'));
// getLight needs to be updated!
}.bind(this), 500);
},
getLight: function(index) {
return this._myArray[index];
}
};
在上面的示例中,getLight(0)
之类的值永远不会更新,因为它们不引用_myArray.*
。但是,我不希望行为的用户每次都必须枚举getLight
的依赖关系。是否有可能告诉Polymer何时需要更新getLight
?