Home  >  Article  >  Web Front-end  >  How to delete data in layui

How to delete data in layui

藏色散人
藏色散人Original
2020-11-09 10:05:174848browse

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.

How to delete data in layui

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to close layui's openNext article:How to close layui's open