jqtree如何获取 json格式里面的值,同时给子节点设背景颜色

[{"text":"组织结构管理","iconCls":"menuOrganizeManagerIcon","draggable":false,"id":"001","children":[{"text"

:"公司基本信息管理","href":"systemmanage/organization/companyManager.jsp","iconCls":"menuCompanyManagerIcon"

,"leaf":true,"hrefTarget":"mainFrame","draggable":false,"id":"001001"},{"text":"部门管理","href":"systemmanage

/organization/departmentManager.jsp","iconCls":"menuDepartmentManagerIcon","leaf":true,"hrefTarget":"mainFrame"

,"draggable":false,"id":"001002"},{"text":"岗位管理","href":"systemmanage/organization/stationManager.jsp"

,"iconCls":"menuStationManagerIcon","leaf":true,"hrefTarget":"mainFrame","draggable":false,"id":"001003"

},{"text":"人事管理","href":"systemmanage/organization/employeeManager.jsp","iconCls":"menuEmployeeManagerIcon"

,"leaf":true,"hrefTarget":"mainFrame","draggable":false,"id":"001004"}]}]

就如我怎么获取 text 对应的值 以此类推,还有就是在页面展示树时怎么给子节点加背景颜色

iteye_3041
iteye_3041 我解决了 代码如下 <body style="width: 100%;"> <div id="tree1" ></div> <script type="text/javascript"> var jsonObj = <%=request.getAttribute("jsonList")%>; $('#tree1').tree({ data: jsonObj, autoOpen: true, dragAndDrop: true, openedIcon:'━', closedIcon:'╋', onCreateLi: function(node, $li) { if(node.type == 7 && node.isCost==1)//获取json里面对应的值 $li.children("div.jqtree-element").children("span").css("background-color","green");//这里就是给每个li加背景颜色 else if(node.type == 6 && node.isCost==1) $li.children("div.jqtree-element").children("span").css("background-color","#ccc999"); else if(node.type == 5 && node.isCost==1) $li.children("div.jqtree-element").children("span").css("background-color","#ffdd00"); else if(node.type == 4 && node.isCost==1) $li.children("div.jqtree-element").children("span").css("background-color","#ccc"); else if(node.type == 3 && node.isCost==1) $li.children("div.jqtree-element").children("span").css("background-color","#hh33ll"); else if(node.type == 2 && node.isCost==1) $li.children("div.jqtree-element").children("span").css("background-color","#tt2233"); else if(node.type == 1 && node.isCost==1) $li.children("div.jqtree-element").children("span").css("background-color","#rr5588"); else if(node.isCost==0) $li.children("div.jqtree-element").children("span").css("background-color","red"); } });
大约 7 年之前 回复

1个回答

var data=[{"text":"组织结构管理"}】
js代码:
for(var i in data){
alert(i);//获取key
if(i=='text'){
alert(data[i]);
}
}
页面展示树时给子节点加背景颜色
构建json串的时候,给子节点添加属性:
font:{'background-color':'black', 'color':'white'}
颜色自己可以设置。

iteye_3041
iteye_3041 我自己解决,但还是谢谢您给我回答,分就给您 <body style="width: 100%;"> <div id="tree1" ></div> <script type="text/javascript"> var jsonObj = <%=request.getAttribute("jsonList")%>; $('#tree1').tree({ data: jsonObj, autoOpen: true, dragAndDrop: true, openedIcon:'━', closedIcon:'╋', onCreateLi: function(node, $li) { if(node.type == 7 && node.isCost==1)//获取json里面对应的值 $li.children("div.jqtree-element").children("span").css("background-color","green");//这里就是给每个li加背景颜色 else if(node.type == 6 && node.isCost==1) $li.children("div.jqtree-element").children("span").css("background-color","#ccc999"); else if(node.type == 5 && node.isCost==1) $li.children("div.jqtree-element").children("span").css("background-color","#ffdd00"); else if(node.type == 4 && node.isCost==1) $li.children("div.jqtree-element").children("span").css("background-color","#ccc"); else if(node.type == 3 && node.isCost==1) $li.children("div.jqtree-element").children("span").css("background-color","#hh33ll"); else if(node.type == 2 && node.isCost==1) $li.children("div.jqtree-element").children("span").css("background-color","#tt2233"); else if(node.type == 1 && node.isCost==1) $li.children("div.jqtree-element").children("span").css("background-color","#rr5588"); else if(node.isCost==0) $li.children("div.jqtree-element").children("span").css("background-color","red"); } });
大约 7 年之前 回复
立即提问
相关内容推荐