我需要在我的javascript中动态删除数据绑定
<my-element-a id="elem_a" label="{{ mylabel }}" value="{{ myvalue }}"></my-element>
<my-element-b id="elem_b" label="{{ mylabel }}" value="{{ myvalue }}"></my-element>
<my-element-c id="elem_c" label="{{ mylabel }}" value="{{ myvalue }}"></my-element>
<my-element-a id="elem_a" label="{{ mylabel }}"></my-element>
<my-element-b id="elem_b" label="{{ mylabel }}" value="{{ myvalue }}"></my-element>
<my-element-c id="elem_c" label="{{ mylabel }}" value="{{ myvalue }}"></my-element>
// 1:
//Result: elem_b.value becomes null.
this.$.elem_a.removeAttribute('value');
// 2:
//Result: both elem_a.label and elem_a.value loses data binding
//Also inside polymer source I saw this was marked as something which would be
//deprecated
this.$.elem_a.unbindAll();
// 3:
//Result: Works but its dirty
//Create a copy of elem_a with its attributes and values
//except the value
var copy = copyAllExcept(elem_a, 'value');
var parent = this.$.elem_a.parentElement;
copy.removeAttribute('value');
parent.removeChild(this.$.elem_a);
parent.appendChild(copy);
//Something like this
this.$.elem_a.unbind('value');
请让我知道如何更好地解决这个问题?
注意:我使用聚合物版本0.3.1
答案 0 :(得分:0)
Polymer正在使用名为TemplateBinding的库。这有一个公共方法来取消绑定模板中的属性。
https://www.polymer-project.org/docs/polymer/template.html#nodeunbind
我试图在聚合物模板中访问此功能,但我无法使其工作。通过一些调查,您可以找到答案。