隐藏输入框用来存储多选产品的id:
<div class="layui-form-item">
<div class="layui-inline">
<label id="label3" class="layui-form-label">选择产品</label>
<div class="layui-input-inline">
<input type="text" autocomplete="off" class="layui-input" id="demo" readonly="readonly">
<input type="hidden" id="templates" name="templates">
</div>
</div>
</div>
js代码,把id的集合赋值给templates:
//下拉表格
var tableSelect = layui.tableSelect;
tableSelect.render({
elem: ‘#demo’,
searchKey: ‘goodsName’,
table: {
url: ,
request: {
limitName: ‘size’,
},
cols: [
[
{type: ‘checkbox’},
{field: ‘id’, title: “ID”, align: ‘center’, width: 65},
{field: ‘name’, title: “名称”, align: ‘center’, width: 600},
{
field: ‘img’, title: “图片”, align: ‘center’, width: 110,
templet: function (d) {
return ‘’;
}
},
{field: ‘specifications’, title: “备注”, align: ‘center’, width: 140},
]
],
parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
return {
“code”: 0, //解析接口状态
“msg”: res.msg, //解析提示文本
“count”: res.count, //解析数据长度
“data”: res.datas//解析数据列表
};
},
},
done: function (elem, data) {
var NEWJSON = [];
var templates = [];
layui.each(data.data, function (index, item) {
NEWJSON.push(item.name);
templates.push(item.id);
});
elem.val(NEWJSON.join(","));
$("#templates").val(templates.join(","));
},
});