小程序,全选,反选,取消选中

//编辑相关操作 //编辑按钮 goEdit() { var self = this let isEdit = !self.data.isEdit self.setData({isEdit: isEdit})//取消编辑的时候,每个编辑选中回到初始态, 全选回到初始态 if (isEdit === false) { let dataList = self.data.goodsList for (let obj of dataList) { obj.edit_choice = false } self.setData({goodsList: dataList, editAllChoice: false}) } }, //编辑时:选择 chooseOne(e) { var self = this let currentItem = e.currentTarget.dataset.item; //当前item在当前goodsList中的下标 debugger var goodsList = self.data.goodsList; let currentIndex = app.tool.mallIndexOfObj(goodsList, currentItem); currentItem.edit_choice = !currentItem.edit_choice; // 在goodsList替换当前item goodsList.splice(currentIndex, 1, currentItem); //判断是否全选 var isAll = true for (let obj of goodsList) { if (!obj.edit_choice) { isAll = false break } } //更新当前数据 self.setData({goodsList: goodsList, editAllChoice: isAll}); },/** * 商城列表根据元素取下标 */ mallIndexOfObj: function (arr, obj) { //console.log('数据源', arr); //console.log('目标数据', obj); for (var index in arr) { //该函数需要兼容套餐活动的商品,做改动兼容 if(obj.product_id){ if (arr[index].product_id === obj.product_id) { return index; } }if(obj.activity_id){ if (arr[index].activity_id === obj.activity_id) { return index; } }} return -1; },

//编辑相关操作
//编辑按钮
goEdit() {
var self = this
let isEdit = !self.data.isEdit
self.setData({isEdit: isEdit})
//取消编辑的时候,每个编辑选中回到初始态, 全选回到初始态 if (isEdit === false) { let dataList = self.data.goodsList for (let obj of dataList) { obj.edit_choice = false } self.setData({goodsList: dataList, editAllChoice: false}) } }, //编辑时:选择 chooseOne(e) { var self = this let currentItem = e.currentTarget.dataset.item; //当前item在当前goodsList中的下标 debugger var goodsList = self.data.goodsList; let currentIndex = app.tool.mallIndexOfObj(goodsList, currentItem); currentItem.edit_choice = !currentItem.edit_choice; // 在goodsList替换当前item goodsList.splice(currentIndex, 1, currentItem); //判断是否全选 var isAll = true for (let obj of goodsList) { if (!obj.edit_choice) { isAll = false break } } //更新当前数据 self.setData({goodsList: goodsList, editAllChoice: isAll}); },

/**
* 商城列表根据元素取下标
*/
mallIndexOfObj: function (arr, obj) {
//console.log('数据源', arr);
//console.log('目标数据', obj);
for (var index in arr) {
//该函数需要兼容套餐活动的商品,做改动兼容
if(obj.product_id){
if (arr[index].product_id === obj.product_id) {
return index;
}
}
if(obj.activity_id){ if (arr[index].activity_id === obj.activity_id) { return index; } }} return -1; },

【小程序,全选,反选,取消选中】现在的人太着急了,看一眼照片,听一段语音,道两天晚安,就喜欢上了。不过讨厌得也很快,喜欢了三五月,最后因为一个眼神,一句话,不到一秒就决定放弃了。多情又冷酷也挺好的,速战速决总是好过暧昧不清,就只怕杀伐决断的遇到了藕断丝连。情意绵绵的遇上了见异思迁,这世上,赢的还是生性薄情之人。

    推荐阅读