Layui 树 保存展开状态


//通过cookie保存展开的节点id
//设置展开id的变量 var open_id_list = []; //判断结构树是否加载完毕 function isOverLoad(){ var loadover = $('.layui-icon.layui-tree-head').html(); if(loadover != undefined){ retention(); }else{ setTimeout(isOverLoad, 1000); } } //初始化 function retention(){ openIdList(); //监听展开按钮 $('.layui-tree-head').click(function(){ setOpenIdList(this); }); } //清除保存的展开id function reset(){ setCookie("open_id_list",'',30); } //展开上次展开的内容 function openIdList(){ if(checkCookie('open_id_list')){ open_id_list = JSON.parse(getCookie('open_id_list')); for (var i=0;i<open_id_list.length;i++){ treeGrid.treeNodeOpen('list',treeGrid.getDataMap('list')[parseInt(open_id_list[i])],true); } } } //将展开行的id推进展开id变量并保存到cookie function setOpenIdList(_self){ //获取行id var id = $(_self).parent().parent().parent().prev().children().children().html(); if(id != undefined){ var index = open_id_list.indexOf(id); if(index < 0){ open_id_list.push(id); }else{ open_id_list.splice(index,1); } setCookie("open_id_list",JSON.stringify(open_id_list),30); } } //获取cookie function getCookie(cname){ var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i<ca.length; i++) { var c = ca[i].trim(); if (c.indexOf(name)==0) { return c.substring(name.length,c.length); } } return ""; } //设置cookie function setCookie(cname,cvalue,exdays){ var d = new Date(); d.setTime(d.getTime()+(exdays*24*60*60*1000)); var expires = "expires="+d.toGMTString(); document.cookie = cname+"="+cvalue+"; "+expires; } //判断cookie是否存在 function checkCookie(cname){ var ProjectBudget=getCookie(cname); if (ProjectBudget!=""){ return true; } return false; }

 

原创文章,作者:254126420,如若转载,请注明出处:https://blog.ytso.com/267852.html

(0)
上一篇 2022年6月19日
下一篇 2022年6月19日

相关推荐

发表回复

登录后才能评论