数组元素的 Polymer 1.0 notifyPath
Polymer 1.0 notifyPath for array element
简单示例:
<template is="dom-repeat" items="{{items}}">
<template is="dom-repeat" items="{{item.subitems}}">
<span>{{item}}</span>
</template>
<span on-tap="add">ADD</span>
</template>
attached: function () {
this.items = [
{ subitems:[] },
{ subitems:[] }
]
},
add: function (e) {
e.model.item.subitems.push("Test");
}
这不会刷新 dom-repeat for {{item.subitems}}。我如何将更改通知 Polymer?
来自docs
Mutations to the items array itself (push, pop, splice, shift, unshift) must be performed using methods provided on Polymer elements, such that the changes are observable to any elements bound to the same array in the tree. For example: this.push('employees', { first: 'Jack', last: 'Aubrey' });
简单示例:
<template is="dom-repeat" items="{{items}}">
<template is="dom-repeat" items="{{item.subitems}}">
<span>{{item}}</span>
</template>
<span on-tap="add">ADD</span>
</template>
attached: function () {
this.items = [
{ subitems:[] },
{ subitems:[] }
]
},
add: function (e) {
e.model.item.subitems.push("Test");
}
这不会刷新 dom-repeat for {{item.subitems}}。我如何将更改通知 Polymer?
来自docs
Mutations to the items array itself (push, pop, splice, shift, unshift) must be performed using methods provided on Polymer elements, such that the changes are observable to any elements bound to the same array in the tree. For example:
this.push('employees', { first: 'Jack', last: 'Aubrey' });