LayUI使用table加载数据之后,列表全选取值问题汇总
一、正常使用table.render()时,
checkStatus = table.checkStatus();
console.log(checkStatus);
checkData = checkStatus.data; (checkData.length === ){
layer.msg(,{icon:});
}
ids=;
(p checkData)
{
it=checkData[p];
ids=ids==?it.artid:ids++it.artid;
}可以通过上述方法取得复选中被选中的值。
二、当table.render中使用了done:function(){}方法之后
,id:"tableIns"
,done:function(){
tableData = table.cache.tableIns;
}此时在使用(一)中所使用的方法将不起作用。通过table.checkStatus().data将获取不到选中的结果。
此时应该将tableData声名为全局变量,在table.render({})中加入done方法,
在取得复选框选中值时使用:
var ids="";
$(".laytable-cell-checkbox").each(function(i,item){
var index=$(item).parent("td").parent("tr").attr("data-index");
if($(item).find(".layui-form-checked").length>0){
var it=tableData[index];
ids=ids==""?it.artid:ids+","+it.artid;
}
});
if(ids=="")
{
return layer.msg('请选择数据',{icon:5});
}以上的区别仅在于在table.render({})中是否使用了done:function(),如果使用了,则使用(二)中使用的方法取得选中的值,否则使用第一种。