easyui 树形菜单 为什么自动异步加载 10
url返回的是这串:[{"id":"M_10001","text":"系统管理","state":"closed"}]但是为什么我的菜单能这样点开?我不想让菜单能这样点开...
url返回的是这串:[{"id":"M_10001","text":"系统管理","state":"closed"}]但是为什么我的菜单能这样点开?我不想让菜单能这样点开,要如何处理?
展开
1个回答
展开全部
没有传父节点id
$('#MyTree').tree({
checkbox: false, //多选属性
url: '<%=contextPath%>/tree/tree_data',
lines:true,
onBeforeExpand:function(node,param){ //点击展开节点是传parentId
$('#MyTree').tree('options').url = '/tree/tree_data?parentId='+node.id;
}, loadFilter:myLoadFilter,
onClick:function(node){
var state=node.state;
if(!state){
//判断当前选中的节点是否为根节点
currentId=node.id;
$("#chooseOk").attr( "disabled" , false );
//如果为根节点 则OK按钮可用
}else{
$("#chooseOk").attr( "disabled" , true );
//如果不为根节点 则OK按钮不可用
}
}
});
function myLoadFilter(data, parent){
var state = $.data(this, 'tree');
function setData(){
var serno = 1;
var todo = [];
for(var i=0; i<data.length; i++){
todo.push(data[i]);
}
while(todo.length){
var node = todo.shift();
if (node.id == undefined){
node.id = '_node_' + (serno++);
}
if (node.children){
node.state = 'closed';
node.children1 = node.children;
node.children = undefined;
todo = todo.concat(node.children1);
}
}
state.tdata = data;
}
setData();
return data;
}
$('#MyTree').tree({
checkbox: false, //多选属性
url: '<%=contextPath%>/tree/tree_data',
lines:true,
onBeforeExpand:function(node,param){ //点击展开节点是传parentId
$('#MyTree').tree('options').url = '/tree/tree_data?parentId='+node.id;
}, loadFilter:myLoadFilter,
onClick:function(node){
var state=node.state;
if(!state){
//判断当前选中的节点是否为根节点
currentId=node.id;
$("#chooseOk").attr( "disabled" , false );
//如果为根节点 则OK按钮可用
}else{
$("#chooseOk").attr( "disabled" , true );
//如果不为根节点 则OK按钮不可用
}
}
});
function myLoadFilter(data, parent){
var state = $.data(this, 'tree');
function setData(){
var serno = 1;
var todo = [];
for(var i=0; i<data.length; i++){
todo.push(data[i]);
}
while(todo.length){
var node = todo.shift();
if (node.id == undefined){
node.id = '_node_' + (serno++);
}
if (node.children){
node.state = 'closed';
node.children1 = node.children;
node.children = undefined;
todo = todo.concat(node.children1);
}
}
state.tdata = data;
}
setData();
return data;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询