1、layui checkbox循环获取选中的值 放到数组里
$("[name=roles]:checkbox").each(function() {
if ($(this).prop("checked") == true) {
roles.push($(this).val());
para.roles = roles;
}
})
2、layui checkbox 只要是选中的当中有【社区店管理】就显示【社区店】下拉框
var roless = [];
form.on('checkbox(roless)', function(data){
roless = [];
$("[name=roles]:checkbox").each(function() {
if ($(this).prop("checked") == true) {
roless.push($(this).val());
}
})
如果roless数组中有 6 就显示下拉框
↓ ↓ ↓ ↓ ↓ ↓
if (roless.indexOf('6') > -1) {
$('[data-role="storelist"]').show();
}else{
$('[data-role="storelist"]').hide();
}
});
3、layui checkbox 根据数组值来回填选中数据
获取数组数据 (res.data.admin.roles) 放到一个新数组中 (rolesArr)
↓ ↓ ↓ ↓ ↓ ↓
$.each(res.data.admin.roles, function(i, v) {
rolesArr.push(v.id);
})
循环checkbox选中数据
↓ ↓ ↓ ↓ ↓ ↓
$('[data-role="editAdminuserLayer"] [name="roles"]').each(function(i, v) {
var id = $(v).attr('value');
id = parseInt(id);
如果id在rolesArr数组中就选中
↓ ↓ ↓ ↓ ↓ ↓
if (rolesArr.indexOf(id) > -1) {
$(v).prop('checked', true);
}
})