Polymer 1.0的notifyPath用于数组元素

时间:2015-06-10 15:35:31

标签: polymer

简单示例:

<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");
}

这不会刷新{{item.subitems}}的dom-repeat。如何通知聚合物变化?

1 个答案:

答案 0 :(得分:2)

来自docs

  

items数组本身的变异(push,pop,splice,shift,unshift)必须使用Polymer元素上提供的方法执行,这样更改对于绑定到树中相同数组的任何元素都是可观察的。例如:this.push('employees', { first: 'Jack', last: 'Aubrey' });