如何通过调用下面的函数取消选中所有复选框 dom-repeat

How to uncheck all the checkbox by calling a function in the below dom-repeat

请帮忙解决这个问题。

<div>
    <template is="dom-repeat" items="{{checkdata}}">
        <paper-checkbox on-tap="checkall" checked="{{item.checked}}"></paper-checkbox>
        <span>{{item.name}}</span>
    </template>
</div>

属性为

checkdata:{
    type: Array,
    value:[{name: 'Bike'},
         {name: 'Car'},
         {name: 'Cycle'},
         {name: 'Bus'},
         {name: 'Truck'}
        ],
}

作为

发挥作用
checkall: function() {
    var checkvalue = this.checkdata;
    var checktext = [];
    for (i = 0; i < checkvalue.length; i++) {
        if (checkvalue[i].checked==true) {
            checktext.push(checkvalue[i].name);
            this.checkeditem = checktext + " ";
        }
    }
}

这是您可以选中或取消选中的函数示例:

checkAll() { 
          let checkdata=[];
          this.checkdata.forEach((i,x)=> {
             checkdata.push({"name": i.name, "checked": true});

             if (x==this.checkdata.length-1){
               this.set('checkdata', checkdata);
               console.log(checkdata);
            }
          })

}

uncheckAll() {
         let checkdata=[];
          this.checkdata.forEach((i,x)=> {
             checkdata.push({"name": i.name, "checked": false});

             if (x==this.checkdata.length-1){
               this.set('checkdata', checkdata);
               console.log(checkdata);
            }
          })

}

Demo

在paper-checkbox的checked属性等号前加一个“$”,像这样:

<paper-checkbox on-tap="checkall" checked$="{{item.checked}}"></paper-checkbox>