微信小程序view多选

在微信小程序里面不使用checkbox怎么实现view的多选

wxml文件


  
     
     {{item.name}}
  

wxss文件

.item_container {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 20rpx;
}
 
.select_icon {
  width: 40rpx;
  height: 40rpx;
}
 
.text {
  margin-left: 30rpx;
}

js文件

data: {
    itemList: [
      { id: 1, name: 'C语言', isSelected: false, },
      { id: 2, name: 'Java', isSelected: false, },
      { id: 3, name: 'C++', isSelected: false, },
    ]
  },
 
itemSelected: function (e) {
    var index = e.currentTarget.dataset.index;
    var item = this.data.itemList[index];
    item.isSelected = !item.isSelected;
    this.setData({
      itemList: this.data.itemList,
    });
  }

效果如图


2018051618.gif

你可能感兴趣的:(微信小程序view多选)