如何在阵列更改时在Polymer中重新渲染完整的dom repeat
我刚开始玩聚合物,一直在努力解决以下问题 在下面的代码中,当单击按钮时,如何在阵列更改时在Polymer中重新渲染完整的dom repeat,polymer,polymer-1.0,Polymer,Polymer 1.0,我刚开始玩聚合物,一直在努力解决以下问题 在下面的代码中,当单击按钮时,myItem数组被更改,父模板dom repeat被重新提交,但子模板dom repeat不会更新 原因可能是子dom repeat绑定到函数\u get <dom-module id="my-element"> <template> <button on-click="_removeLastTwo">switch</button> <templ
myItem
数组被更改,父模板dom repeat
被重新提交,但子模板dom repeat
不会更新
原因可能是子dom repeat绑定到函数\u get
<dom-module id="my-element">
<template>
<button on-click="_removeLastTwo">switch</button>
<template is="dom-repeat" items="{{myItem}}">
<ul>
<template is="dom-repeat" items="{{_get(item)}}">
<li>{{item}}</li>
</template>
</ul>
</template>
</template>
</dom-module>
<script>
Polymer({
is: 'my-element',
properties: {
data: {
type: Array,
value: [9,8]
},
myItem:{
type:Array,
value:[1,2,3,4,5]
}
},
_get:function(t){
var d = this.myItem.length;
return [d+1,d+2]
},
_removeLastTwo: function(){
this.myItem = [1,2]
}
});
</script>
转换
- {{item}}
聚合物({
是‘我的元素’,
特性:{
数据:{
类型:数组,
价值:[9,8]
},
我的项目:{
类型:数组,
值:[1,2,3,4,5]
}
},
_get:函数(t){
var d=this.myItem.length;
返回[d+1,d+2]
},
_removelastwo:function(){
this.myItem=[1,2]
}
});
如何克服此问题,请查看。我是否缺少任何基本方法 喜欢
this.set
或this.push
而不是this.myItems=[1,2]
喜欢this.set
或this.push
而不是this.myItems=[1,2]