angularJS-Ztree

前端之家收集整理的这篇文章主要介绍了angularJS-Ztree前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

官网:http://www.treejs.cn/v3/main.PHP#_zTreeInfo

自定义指令

/**
*name:public.ztree
*Version:1.0.0beta
*/
define(['publicZtree'],function(){
angular.module('public.ztree',[]).directive('tree',[function(){
return{
require:'ngModel',restrict:'A',link:function($scope,element,attrs,ngModel){
varsetting={
data:{
key:{
title:"branchName"
},simpleData:{
enable:true
}
},callback:{
onClick:function(event,treeId,treeNode,clickFlag){
BRANCHID=treeNode.branchId;
BranchID=treeNode.branchId;
$scope.$apply(function(){
ngModel.$setViewValue(treeNode);
});
}
},};

//向控制器发送消息,进行菜单数据的获取
$scope.$emit("treeCtrl",attrs["1"]);
$scope.$on("menuData",function(event,data){//监听或接收数据。。用于接收event与data
$.fn.zTree.init($("#tree"),setting,data);//进行初始化树形菜单
//$.fn.zTree.init(element,data);//进行初始化树形菜单element
varzTree=$.fn.zTree.getZTreeObj("tree");//zTree的DOM容器的id
varselectName=$("#selectName").val();
if(typeofselectName=="undefined"||selectName==""){
zTree.selectNode(zTree.getNodeByParam("tree","1"));//默认第一个选中
$("#selectName").val(zTree.getSelectedNodes()[0]);//赋值
}else{
for(vari=0;i<data.length;i++){
if(data[i]["branchId"]==selectName){
zTree.selectNode(zTree.getNodeByParam("branchId",data[i]["branchId"]));
}
}
}
});


$scope.$on("menuData1",data){//监听或接收数据。。用于接收event与data
$.fn.zTree.init($("#tree1"),data);//进行初始化树形菜单element
varzTree=$.fn.zTree.getZTreeObj("tree");//zTree的DOM容器的id
varselectName=$("#selectName").val();
if(typeofselectName=="undefined"||selectName==""){
//zTree.selectNode(zTree.getNodeByParam("tree","1"));//默认第一个选中
//$("#selectName").val(zTree.getSelectedNodes()[0]);//赋值//因为修改时selectNode是空的赋值失败报错,所以注释
}else{
for(vari=0;i<data.length;i++){
if(data[i]["branchId"]==selectName){
zTree.selectNode(zTree.getNodeByParam("branchId",data[i]["branchId"]));
}
}
}
});


$scope.$on("menuData2",data){//监听或接收数据。。用于接收event与data
$.fn.zTree.init($("#tree2"),data[i]["branchId"]));
}
}
}
});

}
};
}]);
});
控制器
//获取树节点
$scope.$on("treeCtrl",params){
varCoreUrl=newcoreUrl({"transCode":"B000300"});
CoreUrl.$save(function(data){
//发送消息给子控制器
$scope.mechanismList=data.row;
$scope.$broadcast("menuData",$scope.mechanismList);
},function(error){
alert(JSON.stringify(error));
});
$scope.modifyMechanismList=function(){
$('#addUser').modal();
//$('body').removeClass("open_modal");

$scope.BRANCHID=BRANCHID;
varCoreUrl=newcoreUrl({"transCode":"B000300","branchId":$scope.BRANCHID});
CoreUrl.$save(function(objc){
$scope.organization_query2=objc;
$scope.parentBranchId_choose=objc.row[0].branchName;
},function(error){
alert(JSON.stringify(error));
});
};
});
<divclass="modal-body">
<ultreeid="tree"color:#dcdcdc;"class="ztree"ng-model="selectNode"value="1">
</div>

猜你在找的Angularjs相关文章