使用 polymer Templatizer
行为,假设我们一切正常,我们不仅想要 stamp
属性,还有计算函数,应该如何处理呢?
我可以通过指定使其工作
_getRootDataHost: function(){
return this;
}
然而事实证明这样做意味着
<my-element prop="[[value]]"></my-element>
实际上会中断(因为现在在 value
而不是它的父级中查找 <my-element>
)。
需要明确的是,上面允许的是
<my-element>
<template>
<span>{{someComputedProperty(item)}}</span>
</template>
</my-element>
哪里someComputedProperty
定义于 <my-element>
而不是它的容器。
最佳答案
因此,实现此目的的一种极其丑陋的方法是直接在 dataHost
上设置函数,因此我们得到的是在 attached
中调用的函数,它看起来像这样
_registerEvilFunctions: function(){
this.dataHost._pdt_getArrayItemLabel = this._getArrayItemLabel;
this.dataHost._pdt_getValidRegexForInput = this._getValidRegexForInput;
}
不能说我对此感到满意,并且我已确保为其添加足够的前缀以防止冲突,但至少它有效。
关于javascript - 模板化中的自定义计算函数 `<template>`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33765957/