layui implements the method of deleting data: first obtain the current row data and the value corresponding to "lay-event"; then obtain the clicked application position; then loop the data of the array and define a bool; finally pass "obj .del();" Delete the DOM structure of the corresponding line and update the cache.
Recommended: "layui tutorial"
layui——Delete table data (array data)
The code is as follows:
table.on('tool(dataTable)', function(obj) { //注:tool是工具条事件名,test是table原始容器的属性 lay-filter="对应的值" var data = obj.data; //获得当前行数据 var layEvent = obj.event; //获得 lay-event 对应的值 //获取点击的应用位置 if (layEvent == 'delete') { layer.confirm('确认删除吗?', function(index) { mans.forEach((item, index) => {//先循环数组的数据 let bool = item.userId == data.userId;//定义一个bool如果数据的id和当前行数据相等 if (bool) { mans.splice(index, 1); } }); console.log(mans); obj.del(); //删除对应行(tr)的DOM结构,并更新缓存 layer.close(index); }); } });
The above is the detailed content of How to delete data in layui. For more information, please follow other related articles on the PHP Chinese website!