Polymer 阵列元件的聚合物1.0路径
简单的例子:Polymer 阵列元件的聚合物1.0路径,polymer,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>
<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}}
添加
附:函数(){
此项。项目=[
{子项:[]},
{子项:[]}
]
},
加:职能(e){
e、 模型.item.subitems.push(“测试”);
}
这不会刷新{{item.subitems}的dom重复。如何将更改通知polymer?从
必须使用聚合物元素上提供的方法对项目数组本身(推送、弹出、拼接、移位、取消移位)进行突变,这样,树中绑定到同一数组的任何元素都可以观察到变化。例如:this.push('employees',{first:'Jack',last:'Aubrey'})代码>
我认为这只适用于将元素推送到项目,而不适用于子项目。有点不太正常,但我成功地做到了:var arrayLoc=e.model.\uuuuuu key\uuuuu代码>var stringLoc=“items.”+arrayLoc+“.subitems”代码>this.push(stringLoc,“test”)代码>很抱歉,我尝试了这个,但它不起作用:this.push(“item.subitems”,“Test”)。我认为可以使用元素的索引,如“items.3.subitems”,但必须有一种更简单的方法?经过一些测试后,我认为正确的方法是:e.model.push(“item.subitems”,“Test”)