亲宝软件园·资讯

展开

微信小程序checkbox组件 微信小程序checkbox组件使用详解

Rattenking 人气:0
想了解微信小程序checkbox组件使用详解的相关内容吗,Rattenking在本文为您仔细讲解微信小程序checkbox组件的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:微信小程序,checkbox,下面大家一起来学习吧。

本文为大家分享了微信小程序checkbox组件的使用方法,供大家参考,具体内容如下

效果图

checkbox组件效果图

WXML

<view class="tui-content">
 <checkbox-group bindchange="checkboxChange">
 <label class="checkbox" wx:for="{{items}}">
  <view class="tui-menu-list"><checkbox value="{{item.name}}" checked="{{item.checked}}"/>{{item.value}}</view>
 </label>
 </checkbox-group>
 <view class="tui-show-name">
 <text wx:for="{{checkArr}}"> {{item}} </text>
 </view>
</view>

JS

Page({
 data: {
 items: [
  { name: 'USA', value: '美国' },
  { name: 'CHN', value: '中国', checked: 'true' },
  { name: 'BRA', value: '巴西' },
  { name: 'JPN', value: '日本' },
  { name: 'ENG', value: '英国' },
  { name: 'TUR', value: '法国' },
 ],
 checkArr: ['中国']
 },
 checkboxChange: function (e) {
 var arr = [];
 e.detail.value.forEach(current => {
  for (var value of this.data.items){
  if(current === value.name){
   arr.push(value.value);
   break;
  } 
  }
 });
 this.setData({checkArr: arr});
 }
})

总结

DEMO下载

加载全部内容

相关教程
猜你喜欢
用户评论