[英]How to unbind property in Polymer 1.0
In Polymer 1.0 we can bind an element property to a variable: 在Polymer 1.0中,我们可以将element属性绑定到变量:
<paper-textarea id='area' value={{some_variable}}></paper-textarea>
How can I unbind it? 我怎么解开呢?
Below is a solution that doesn't works for me. 以下是一个对我不起作用的解决方案。 When
some_variable
changes it updates area value. 当
some_variable
更改时,它会更新区域值。
this.$.area.value = "foo";
You can't dynamically bind and/or unbind to element attributes in Polymer 1.0, because bindings are baked during element registration time, not during created/ready/attached. 您无法动态绑定和/或取消绑定到Polymer 1.0中的元素属性,因为绑定在元素注册时间内烘焙,而不是在创建/准备/附加期间烘焙。 Ref Binding imperatively
参考绑定势在必行
Honestly I'm not exactly sure what your use-case is; 老实说,我不确定你的用例是什么; however, it highly likely that you can achieve it by a) binding your
value
attribute to a computed function ; 但是,很有可能你可以通过a)将你的
value
属性绑定到一个计算函数来实现它; or b) bind to a dummy variable 或b)绑定虚拟变量
<paper-textarea id='area' value={{letsCompute(some_variable)}}></paper-textarea>
...
letsCompute: function (v) {
//return your logic to bind or unbind
},
...
It is not 100% clear what you are trying to achieve, but with Polymer you can do one-way data binding. 它不是100%清楚你要实现的目标,但使用Polymer,你可以进行单向数据绑定。
Downward binding: 向下绑定:
<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>
Upwards binding: 向上绑定:
<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>
Check out the documentation for more information. 查看文档以获取更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.