2

我正在尝试在 dom-repeater 和模板中的输入之间创建双向数据绑定,但更改似乎不会传播回来。我究竟做错了什么?

<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 中继器中的输入不会传播,它外部的输入使用路径传播到中继器,但不是相反,但它不会更新{{}}.

4

2 回答 2

2

我问了一个类似的问题(How to two-way bind iron-input to dom-repeat's item?)我得到的答案是使用value="{{item::input}}. 但是,绑定到原始字符串数组似乎效果不佳。我尝试将其更改为具有单个字符串属性的对象数组,并且做到了。

http://plnkr.co/edit/X6b3FqZIY29tiGYoHnzq

于 2015-06-10T15:24:31.340 回答
0

这是我如何处理嵌套 dom-repeat 中更改的数据

http://plnkr.co/edit/Y0P5vNxg46t5fX7gJFxU?p=preview

// Add Task to the selected Employee
_addTask: function() {
 var i=this._getSelectedEmployeeIndex()
 if (i>=0) {
   var employee = this.employees[i]
   // use both for child dom-repeat
   this.push('employees.'+i+'.tasks', {name: this._random(this.__tasks)})
   this.notifyPath('employees.'+i+'.tasks.*')
 }
},
于 2016-11-01T03:19:36.123 回答