How to delete data in layui

藏色散人
Release: 2020-11-17 15:29:44
Original
4775 people have browsed it

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); }); } });
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!