我正在尝试在修改列表时刷新dom-repeat但它不起作用
我和本例中的做法相同:
How can i force a template-update in Polymer?
这是我的代码:
<link rel="import" href="../bower_components/polymer/polymer.html">
<!-- <link rel="import" href="./bower_components/paper-button/paper-button.html"> -->
<dom-module id="hola-mundo">
<template>
<button on-tap="sort">order by name</button>
<table>
<template id="tpl" is="dom-repeat" items="{{list}}">
<tr>
<td>{{item.id}} - {{item.name}}</td>
</tr>
</template>
</table>
</template>
</dom-module>
<script>
Polymer(
{
is: "hola-mundo",
properties:
{
list: {type: Array, value: [{id:0,name:"First"}
,{id:4,name:"Fifth"}
,{id:1,name:"Second"}
,{id:2,name:"Third"}
,{id:3,name:"Fourth"}
,{id:5,name:"Last"}
]}
},
sort: function(e)
{
this.list.sort(function (a, b) {
if (a.name > b.name) {
return 1;
}
if (a.name < b.name) {
return -1;
}
return 0;
});
for(let i=0; i< this.list.length; i++){
this.notifyPath("list." + i + ".name",this.list[i].name);
}
debugger
}
});
</script>
当我们按下“按名称排序”按钮时,为什么不显示排序?有人可以修复我的代码吗?
非常感谢你