在Polymer 1.0中,我们可以将element属性绑定到变量:
<paper-textarea id='area' value={{some_variable}}></paper-textarea>
我如何解开它?
以下是一个对我不起作用的解决方案。当some_variable
更改时,它会更新区域值。
this.$.area.value = "foo";
答案 0 :(得分:2)
您无法动态绑定和/或取消绑定到Polymer 1.0中的元素属性,因为绑定是在元素注册时间内烘焙,而不是在创建/准备/附加期间烘焙。参考Binding imperatively
老实说,我不确定你的用例是什么;但是,很有可能你可以通过a)将value
属性绑定到计算函数来实现它;或b)绑定虚拟变量
<paper-textarea id='area' value={{letsCompute(some_variable)}}></paper-textarea>
...
letsCompute: function (v) {
//return your logic to bind or unbind
},
...
答案 1 :(得分:1)
您想要实现的目标并非100%明确,但使用Polymer,您可以进行单向数据绑定。
向下绑定:
<script>
Polymer({
is: 'custom-element',
properties: {
prop: String // no notify:true!
}
});
</script>
...
<!-- changes to "value" propagate downward to "prop" on child -->
<!-- changes to "prop" are not notified to host due to notify:falsey -->
<custom-element prop="{{value}}"></custom-element>
向上绑定:
<script>
Polymer({
is: 'custom-element',
properties: {
prop: {
type: String,
notify: true,
readOnly: true
}
}
});
</script>
...
<!-- changes to "value" are ignored by child due to readOnly:true -->
<!-- changes to "prop" propagate upward to "value" on host -->
<custom-element prop="{{value}}"></custom-element>
查看documentation了解详情。