我正在尝试使用Polymer v1.7.0实现自定义过滤器。但是,它根本不起作用;当我尝试使用过滤器时,输出只是原始表达式,未经处理。
我尝试过就像在这里完成的那样:https://github.com/PolymerLabs/polymer-patterns/blob/master/snippets/filters/using-custom-filters.html但是使用了这段代码:
<div id="toFixed">{{10.123456789 | toFixed(2)}}</div>
仅导致
结果文档中的 {{10.123456789 | toFixed(2)}}
。
我的关联来源是否已过时?我在Polymer文档中找不到任何有价值的信息,因此我们很高兴向右推进这个方向。
答案 0 :(得分:1)
您不需要在Polymer 1.x中pipe
来实现此目的。您可以直接调用函数并将其传递给您想要的值
<base href="https://polygit.org/components/">
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="polymer/polymer.html">
<dom-module id="my-element">
<template>
{{format(myVal)}}
<br>{{format("hello")}}
</template>
</dom-module>
<script>
Polymer({
is: "my-element",
properties: {
myVal: {
type: String,
value: "Hi"
}
},
format: function(input) {
return input + " John";
}
});
</script>
<my-element></my-element>
&#13;