easyUI accordion 使用和remove方法 for循环的异常

姬英武
2023-12-01
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/WEB-INF/jsp/common/easyUi.jsp"%>
</head>
<body class="easyui-layout">
	<div data-options="region:'north',border:false" style="height:60px;background:#B3DFDA;padding:10px">
		<ul class="nav nav-pills navbar-pos">
            <li role="presentation"><a href="#" path="index/home" datatype="system">系统管理</a></li>
       		<li role="presentation"><a href="#" οnclick="logout()">退出登录</a></li>
        </ul>
	
	</div>
	<div class='sss' data-options="region:'west',split:true,title:'导航菜单'" style="width:150px;padding:0px;">
		<div class="easyui-accordion left_options" data-options="fit:true,border:false">
			<div title="Title1" style="padding:10px;">
				content1
			</div>
			<div title="Title2" data-options="selected:true" style="padding:10px;">
				content2
			</div>
			<div title="Title3" style="padding:10px">
				content3
			</div>
		</div>
	
	</div>
	<div data-options="region:'east',split:true,collapsed:true,title:'East'" style="width:100px;padding:10px;">east region</div>
	<div data-options="region:'south',border:false" style="height:50px;background:#A9FACD;padding:10px;">south region</div>
	<div data-options="region:'center',title:'Center'" style="border:false;overflow: hidden;">
		<iframe src="${path}/role/2" id="myIframe" name="myIframe" style="width:100%;height:100%;border:false;overflow: hidden;"></iframe>
	</div>
	
<script type="text/javascript">
//$(function(){
var system = [
	{cname: "组织机构",igclass:"fa",iclass:"fa-users", path:"user", childrens: [
          {cname: "用户管理",igclass:"fa",iclass:"fa-users", path:"user", childrens: []},
          {cname: "角色管理",igclass:"glyphicon",iclass:"glyphicon-tint", path:"role/2", childrens: []},
          {cname: "权限管理",igclass:"glyphicon",iclass:"glyphicon-tint", path:"auth", childrens: []}
	]},{cname: "角色机构",igclass:"fa",iclass:"fa-users", path:"user", childrens: [
          {cname: "角色管理",igclass:"glyphicon",iclass:"glyphicon-tint", path:"role", childrens: []},
          {cname: "权限管理",igclass:"glyphicon",iclass:"glyphicon-tint", path:"auth", childrens: []}
	]}
];
            
//})

$(function(){

})

$(".nav>li").click(function(){
	$(this).addClass("active");
	$(this).siblings().removeClass("active");
	var ask = $(this).attr("accesskey");
    var a=$(this).children("a");
	var datatype = $(a).attr("datatype");
	console.info(datatype);
	var pnl = $(".left_options").accordion("panels");
	var titles='';
	if (pnl){
		$.each(pnl, function(i) {
			var title = pnl[i].panel("options").title;
    		titles += title+',';
		})
	} 
	var arr_title = new Array(); 
	arr_title = titles.split(",");
	for (i=0;i<arr_title.length ;i++ ) 
	{ 
		if(arr_title[i] != ""){
			$('.left_options').accordion("remove",arr_title[i]);
		}
	} 
	left_opt = eval(datatype);
	html = '';
	$.each(left_opt, function(i) {
	var result = left_opt[i];
		if (i == 0) {//显示第一个一级菜单下的二级菜单  
		    $('.left_options').accordion('add', {  
		        title : left_opt[i].cname,  
		        iconCls : left_opt[i].iclass,  
		        selected : true,  
		        content : function(){  
		        	var children = left_opt[i].childrens;
		        	var html = '';
		        	html += '<div class="" style="padding:10px"><ul class="" name="'+left_opt[i].cname+'">';
		        	$.each(children, function(i) {
						html += '<li><a href="javascript:center_show(\''+children[i].path+'\');" path="'+children[i].path+'">'+children[i].cname+'</a></li>';
					})
		        	html += '</ul></div>';
	                return html;  
	            }   
		    });  
		} else {  
		    $('.left_options').accordion('add', {  
		        title : left_opt[i].cname,  
		        iconCls : left_opt[i].iclass,  
		        selected : false,  
		        content : function(){  
		        	var children = left_opt[i].childrens;
		        	var html = '';
		        	html += '<sec:authorize ifAllGranted="/role/2"><div class="" style="padding:10px"><ul class=""  name="'+left_opt[i].cname+'">';
		        	$.each(children, function(i) {
						html += '<li><a href="javascript:center_show(\''+children[i].path+'\');" path="'+children[i].path+'">'+children[i].cname+'</a></li>';
					})
		        	html += '</ul></div></sec:authorize>';
	                return html;  
	            }  
		    });  
		} 
	
	})
});


function center_show(url){
	document.getElementById("myIframe").src="${pageContext.request.contextPath}/"+url;
}

function logout(){
       	window.location.href="${pageContext.request.contextPath}"+"/j_spring_security_logout";
       }
</script>
</body>
</html>
是在清除titile的时候,不能放在for里面直接删除,所以放在数组里面在循环删除这样能解决掉
 类似资料: