Flask接口签名sign原理与实例代码浅析
255
2023-06-07
基于cookie实现zTree树刷新后展开状态不变
基于cookie实现zTree树刷新后,展开状态不变。
1、除了引用jquery和zTree的js外,引用cookie的JS:
2、JS代码:
$(function () {
//ztree设置
var setting = {
data: {
simpleData: {
enable: true,
idKey: "id",
pIdKey: "pId",
rootPId: null
}
},
callback: {
onExpand: onExpand,
onCollapse: onCollapse
}
};
$.ajax({
type: "POST",
url: "/Tech/TemplateTypeManage/GetData",
success: function (data) {
if (data && data.length != 0) {
$.fn.zTree.init($("#tree"), setting, data);
var treeObj = $.fn.zTree.getZTreeObj("tree");
var cookie = $.cookie("z_tree" + window.location);
if (cookie) {
z_tree = JSON2.parse(cookie);
for (var i = 0; i < z_tree.length; i++) {
var node = treeObj.getNodeByParam('id', z_tree[i])
treeObj.expandNode(node, true, false)
}
}
}
}
});
});//end $
function onExpand(event, treeId, treeNode) {
var cookie = $.cookie("z_tree" + window.location);
var z_tree = new Array();
if (cookie) {
z_tree = JSON2.parse(cookie);
}
if ($.inArray(treeNode.id, z_tree) < 0) {
z_tree.push(treeNode.id);
}
$.cookie("http://z_tree" + window.location, JSON2.stringify(z_tree))
}
function onCollapse(event, treeId, treeNode) {
var cookie = $.cookie("z_tree" + window.location);
var z_tree = new Array();
if (cookie) {
z_tree = JSON2.parse(cookie);
}
var indhttp://ex = $.inArray(treeNode.id, z_tree);
z_tree.splice(index, 1);
for (var i = 0; i < treeNode.children.length; i++) {
index = $.inArray(treeNode.children[i].id, z_tree);
if (index > -1) z_tree.splice(index, 1);
}
$.cookie("z_tree" + window.location, JSON2.stringify(z_tree))
}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~