MQ发送接受消息,获取后台返回的数据,然后自己进行封装成tree里面所需要的json格式!里面主要用到异步加载tree的方法!
$("#tree").tree({
data:jsonstring,
//显示加减号
lines:true,
animate:true,
//展开前
onBeforeExpand:function(node){
// 异步加载的地址并传递参数
// $("#tree").tree("options").url ="?"+node.id;
//alert(node.parentpath+ "/" + node.text);return;
var treeObjFinall = eval("(" + treeString + ")");
// treeObjFinall.subdir = new Object()
treeObjFinall.subdir.currpath = node.parentpath+ "/" + node.text;
var treeStringFinall = JSON.stringify(treeObjFinall);
//alert(treeStringFinall);return;
var treeChinArray = new Array();
$.post(SITE_BASE_PATH+"MachineInfo/machineChinPath", {planCount:treeStringFinall},function(result){//这是我后台的地址,主要用于获取参数
//alert(result[0].);
if(result){
for(var i=0;i<result.length;i++){
var getchinObject = new Object();
getchinObject.parentpath=result[i].parentpath;//这里进行了数据的封装
getchinObject.id=i;
getchinObject.text=result[i].path;
if(1 == result[i].state){
getchinObject.state = "closed";
}else{
getchinObject.state = "open";
}
treeChinArray.push(getchinObject);
}
// alert(node.target);
$("#tree").tree('append',{//这里是展示子节点的方法!
parent:node.target,
data:treeChinArray
});
}
},"JSON");
},
onSelect: function (item) {
//alert(item.parentpath+"/"+item.text);
$("#localFile").val(item.parentpath+"/"+item.text);//这个是被选中的方法
}
});