[英]Polymer dom-repeat sub property changes child to host wiring
I have a host element binding array of object to child element which has a paper-input
to edit its properties. 我有一个将对象与子元素绑定在一起的主机元素绑定数组,该子元素具有用于编辑其属性的
paper-input
。 I don't see the value change on input reflected in the host div
element. 我看不到主机
div
元素中反映的输入值变化。 Even though on debug I can see that the host object has the latest edited name
. 即使在调试时,我也可以看到主机对象具有最新编辑的
name
。 What should I do to get this automatically wired ? 我该怎么做才能自动连线?
<!-- Host element -->
<dom-module id="host-item">
<template>
<div>
<div>[[selectedEmployee.name]]</div>
<template is="dom-repeat" items="[[employees]]" as="employee">
<item-edit item="[[employee]]"></item-edit>
</template>
</div>
</template>
<script>
Polymer({
is: 'host-item',
properties: {
selectedEmployee: {
type: Object
},
employees: {
type: Array,
value = [ { name: 'Name 1'}, { name: 'Name 2'}, { name: 'Name 2'}]
}
},
ready: function() {
this.selectedEmployee = this.employees[0];
}
});
</script>
</dom-module>
<!-- Child element -->
<dom-module id="item-edit">
<template>
<paper-input id="input" value="{{item.name}}" error-message="Invalid name!"></paper-input>
</template>
<script>
Polymer({
is: 'item-edit',
properties: {
item: {
type: Object
}
}
});
</script>
</dom-module>
Use {{employee}}
for 2 way binding . 使用
{{employee}}
进行双向绑定 。 [[...]]
is for one way only. [[...]]
仅限于一种方式。 Use notify: true on property definition. 在属性定义上使用notify:true 。
Child element should be defined before the parent. 子元素应该在父元素之前定义。
Here is the working example Plunk , and similar Plunk 这是Plunk的工作示例,以及类似的Plunk
<item-edit item="{{employee}}"></item-edit>
...
employee: {
type: Object,
notify: true,
value: function () { return {name: 'Test' }; }
}
Update: 更新:
Now "employees" data is in form of an array of objects. 现在,“员工”数据采用对象数组的形式。 Check out this question for working with arrays: Polymer, issue with binding array to paper slider value
查看这个问题以使用数组: 聚合物,问题与绑定数组到纸张滑块值
Docs: Binding to array items 文档: 绑定到数组项
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.