After using the WeChat applet for two days, I found that TMD is really convenient, JS is really a lot less, and the responsive layout really saves developers a lot of things.
Here is the html code
<view class="weui-cells weui-cells_form">
<view class="weui-cell weui-cell_active {{isWaring ? 'weui-cell_warn' : ''}}">
<view class="weui-cell__hd">
<label class="weui-label">跟单</label>
</view>
<view class="tui-content">
<checkbox-group bindchange="checkboxChange2">
<label class="checkbox" wx:for="{{gendanItems}}">
<view class="tui-menu-list">
<checkbox value="{{item.empNo}}" checked='{{filter.isChecked2(item.empNo,selectData2)}}' />{{item.name}}</view>
</label>
</checkbox-group>
</view>
</view>
</view>
Here I wrote this thing in the html code, mainly echoed in the js file and I have to assign true to the checked attribute of the object one by one.
<wxs module="filter">
var isChecked2 = function(empNo, data) {
if (empNo != null) {
return data.indexOf(empNo) != -1 ? true : false;
}
return false;
}
module.exports = {
isChecked2: isChecked2,
}
</wxs>
gendanItems is a collection object. I wrote it in java on the back end, and a List <bean> is passed from the back end. Here you can understand it.
selectData2 is the selected array captured in my js.
Paste the code
showClearBtn: false,
selectData2: [] //记住要给个初始值,不然会报错,就这样[]也都可以。
},
checkboxChange2: function(e) {
var up = "pho.gendans2"; //pho是个对象后面的gendans2就是selectData2 可以直接拿给它
this.setData({
[up]: e.detail.value
});
},
That's it.