Templatized“<template>”

时间:2015-11-17 20:03:36

标签: javascript polymer polymer-1.0

使用Polymer Templatizer行为,让我们说我们已经完成了所有工作,我们不仅要stamp属性,还要计算函数,应该怎么做?< / p>

我可以通过指定

来实现它
_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>而不是它的容器。

1 个答案:

答案 0 :(得分:0)

所以,实现这一点的一个非常难看的方法是直接在dataHost上设置函数,所以我们得到的是attached中调用的函数,看起来像这样

_registerEvilFunctions: function(){
    this.dataHost._pdt_getArrayItemLabel = this._getArrayItemLabel;
    this.dataHost._pdt_getValidRegexForInput = this._getValidRegexForInput;
}

不能说我对它感到满意,而且我已经确保为它添加足够的前缀以防止碰撞,但至少它是有效的。

相关问题