layui 樹形結構刪除沒有確認,原始碼加入confirm確認提示框

jiaojinnaozhier發表於2019-09-26
var index = layer.confirm('是否刪除', {
                    btn: ['同意',"取消"], //按鈕
                    shade: false //不顯示遮罩
                }, function(){
                    layer.close(index);
                    if (r.operate && r.operate(x), x.status = "remove", !e.prev("." + s)[0] && !e.next("." + s)[0] && !e.parent("." + y)[0]) return e.remove(), void n.elem.append(n.elemNone);
                    if (e.siblings("." + s).children("." + u)[0]) {
                        if (r.showCheckbox) {
                            var I = function (e) {
                                if (e.parents("." + s)[0]) {
                                    var a = e.siblings("." + s).children("." + u), r = e.parent("." + y).prev(),
                                        l = r.find('input[name="layuiTreeCheck"]')[0], t = 1, d = 0;
                                    0 == l.checked && (a.each(function (e, a) {
                                        var n = i(a).find('input[name="layuiTreeCheck"]')[0];
                                        0 != n.checked || n.disabled || (t = 0), n.disabled || (d = 1)
                                    }), 1 == t && 1 == d && (l.checked = !0, n.renderForm("checkbox"), I(r.parent("." + s))))
                                }
                            };
                            I(e)
                        }
                        if (r.showLine) {
                            var T = e.siblings("." + s), L = 1, N = e.parent("." + y);
                            layui.each(T, function (e, a) {
                                i(a).children("." + y)[0] || (L = 0)
                            }), 1 == L ? (g[0] || (N.removeClass(k), T.children("." + y).addClass(m), T.children("." + y).children("." + s).removeClass(C)), e.next()[0] ? N.children("." + s).last().children("." + y).children("." + s).last().addClass(C) : e.prev().children("." + y).children("." + s).last().addClass(C), e.next()[0] || e.parents("." + s)[1] || e.parents("." + s).eq(0).next()[0] || e.prev("." + s).addClass(C)) : !e.next()[0] && e.hasClass(C) && e.prev().addClass(C)
                        }
                    } else {
                        var H = e.parent("." + y).prev();
                        if (r.showLine) {
                            H.find("." + c).removeClass("layui-tree-icon"), H.find("." + c).children(".layui-icon").removeClass(h).addClass("layui-icon-file");
                            var S = H.parents("." + y).eq(0);
                            S.addClass(k), S.children("." + s).each(function () {
                                i(this).children("." + y).children("." + s).last().addClass(C)
                            })
                        } else H.find(".layui-tree-iconArrow").addClass(t);
                        e.parents("." + s).eq(0).removeClass(v), e.parent("." + y).remove()
                    }
                    e.remove()
                },function() {
                    layer.close(index);
                })

在tree.js裡直接搜尋 e.remove() ;這一塊就是他的三個圖示【add:新增,update:修改,del:刪除】操作程式碼;然後把else裡面的程式碼全部複製到confirm同意的回撥函式中就可以了,頁面裡del函式裡直接寫與後端互動的刪除介面就可以了。

相關文章