數據字典node
以爲通常,依賴 ztree bootStrapdom
1 /** 2 * 數據字典指令。 3 * dictype:數據字典別名。 4 */ 5 .directive('htDic', function($injector){ 6 return { 7 restrict: 'A', 8 scope:{ 9 htDic:'=' 10 }, 11 template:getDirectiveTplHtml("htDic"), 12 link: function(scope, element, attrs) { 13 element.removeClass(); 14 //scope.validate = attrs.validate; 15 scope.permission =getPermission(attrs.permission,scope); 16 var dicKey =attrs.dickey; //數據字典的類型 17 var url=attrs.url|| __ctx +"/system/dataDict/getByTypeKeyForComBo?typeKey="+dicKey; 18 var keyName =attrs.keyName||"key"; 19 var valName=attrs.valName||"text"; 20 21 scope.treeId = parseInt(Math.random()*1000) 22 scope.dicData={}; 23 scope.treeClick = function(event,treeId,treeNode){ 24 scope.dicData.key =treeNode[keyName]; 25 scope.dicData.value =treeNode[valName]; 26 scope.htDic =scope.dicData.key; 27 28 $('#dropBody'+treeId).dropdown('close'); 29 !scope.$parent.$$phase&&scope.$parent.$digest(); 30 } 31 32 scope.loadOrgTree = function(){ 33 new ZtreeCreator(scope.treeId,url) 34 .setDataKey({idKey:keyName,name:valName}) 35 .setCallback({onClick:scope.treeClick}) 36 .setChildKey() 37 //.setOutLookStyle() 38 .initZtree({},1,function(treeObj,treeId){ 39 $('#dropBody'+treeId).dropdown({justify: '#dropDown'+treeId}); 40 41 // 經過key 回顯Value 42 if(scope.htDic){ 43 //獲取key 的那個Value 44 var node = treeObj.getNodesByFilter( function(node){ if(node[keyName]==scope.htDic) return true; else return false; },true); 45 if(node){ 46 scope.dicData.key =node[keyName]; 47 scope.dicData.value =node[valName]; 48 !scope.$parent.$$phase&&scope.$parent.$digest(); 49 } 50 } 51 }); 52 } 53 scope.loadOrgTree(); 54 } 55 }; 56 })