我正在尝试在 dom-repeater 和模板中的输入之间创建双向数据绑定(bind),但更改似乎不会传播回来。我做错了什么?
<dom-module id="record-card">
<template id="node">
<template is="dom-repeat" items="{{labels}}">
<h1>
<input is="iron-input" bind-value="{{item}}" on-change="labelsChanged">
</h1>
</template>
<input is="iron-input" bind-value="{{labels.0}}">
Labels: <span>{{labels}}</span>
</template>
</dom-module>
<script>
Polymer({
is: "record-card",
properties: {
labels: {
type: Array,
notify: true,
value: function() {
return ["Pizza", "Person"]
}
}
}
});
</script>
dom 中继器中的输入不会传播,使用路径的外部输入会传播到中继器中,但反之则不然,但它不会更新 {{}}
.
最佳答案
我问了一个类似的问题( How to two-way bind iron-input to dom-repeat's item? ),我得到的答案是使用 value="{{item::input}}
。但是,它似乎绑定(bind)到原始数组字符串的效果不太好。我尝试将其更改为具有单个字符串属性的对象数组,结果成功了。
关于polymer - dom-repeater 中的两种方式数据绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30738764/