模板化`<中的自定义计算函数;模板>`

Custom computed functions in Templatized `<template>`

本文关键字:计算 函数 模板 自定义 gt lt      更新时间:2023-09-26

使用聚合物Templatizer行为,假设我们让它全部工作,我们不仅想要stamp属性,还想要计算函数,应该如何进行?

我可以通过指定使其工作

_getRootDataHost: function(){
  return this;
}

然而,事实证明,这样做意味着

<my-element prop="[[value]]"></my-element>

实际上断开了(因为现在在<my-element>中查找value而不是它的父级)。

需要明确的是,上面允许的是

<my-element>
 <template>
  <span>{{someComputedProperty(item)}}</span>
 </template>
</my-element>

其中CCD_ 5是在CCD_。

因此,实现这一点的一种极其丑陋的方法是直接在dataHost上设置函数,因此我们得到的是在attached中调用的函数,它看起来像

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

不能说我对它很满意,我已经确保在它前面加上足够的前缀以防止碰撞,但至少它有效。