多选框
页面
tools需要引入,主要作用就是为了获取下标的值,下方标注
<view class="borderclass" style="width: 29%;border-right: 1px dashed #1abc9c;font-size: 28rpx;">
<checkbox-group bindchange="check" data-gid="0">
<view>
<checkbox style="margin:3px 2px 0px 6px" value="1"
checked="{{tools.indexOf(List.inspectionMethodId, '1') }}"></checkbox>实地勘验
<checkbox style="margin:3px 2px 0px 6px" value="2"
checked="{{tools.indexOf(List.inspectionMethodId, '2') }}"></checkbox>查验证照
<checkbox style="margin:3px 2px 0px 6px" value="3"
checked="{{tools.indexOf(List.inspectionMethodId, '3') }}"></checkbox>现场询问
<checkbox style="margin:3px 2px 0px 6px" value="4"
checked="{{tools.indexOf(List.inspectionMethodId, '4') }}"></checkbox>查阅资料
<checkbox style="margin:3px 2px 0px 6px" value="5"
checked="{{tools.indexOf(List.inspectionMethodId, '5') }}"></checkbox>网上核验
</view>
</checkbox-group>
</view>
Js
data:{
List:{
inspectionMethodId:'',
resultId:'',
}
}
//获取选中的值
check(e) {
this.setData({
['List[' + e.currentTarget.dataset.gid + '].inspectionMethodId']: e.detail.value
})
},
回填值,只选在onload中setdata赋值即可
onload:function(option){
this.setData({
['List.inspectionMethodId']:inspectionMethodId,
})
}
需要引用的文件
function indexOf(arr, value) {
if (arr.indexOf(value) < 0) {
return false;
} else {
return true;
}
}
module.exports.indexOf = indexOf;
单选框
页面
<view class="borderclass" style="width: 28%;">
<radio-group bindchange="radi" data-gid="18">
<view>
<radio style="margin: 3px 2px 0px 6px;;" checked="{{List.resultId=='1'}}"
value="1">
合格</radio>
<radio style="margin: 3px 2px 0px 6px;" checked="{{List.resultId=='2'}}" value="2">不合格</radio>
</view>
</radio-group>
</view>
Js
radi(e) {
this.setData({
['List[' + e.currentTarget.dataset.gid + '].resultId']: e.detail.value
})
},
回填值,只选在onload中setdata赋值即可
onload:function(option){
this.setData({
['List.resultId']:resultId,
})
}