Extjs
1 var productCategoryTreeLookUpFn = function(callback) { 2 var productCategoryLookUpWindow; 3 var productCategoryTreeStore; 4 var productCategoryTreeMenu; 5 6 if (!productCategoryLookUpWindow) { 7 8 // 加载菜单树 9 productCategoryTreeStore = Ext.create('Ext.data.TreeStore', { 10 fields : ['id', 'text'], 11 proxy: { 12 type: 'ajax', 13 url: COMMON.APP_URL + '/view/master/selectProductCategoryForComboBoxTree.action' 14 }, 15 root: { 16 id: '0', 17 text : "产品分类", 18 expanded: true 19 } 20 }); 21 22 var beforNode = null; 23 productCategoryTreeMenu = Ext.create('Ext.tree.Panel', { 24 store: productCategoryTreeStore, 25 rootVisible : false, 26 height : 300, 27 animate : true, // 开启动画效果 28 enableDD : false, // 不允许子节点拖动 29 border : false, // 没有边框 30 singleClickExpand : true, 31 listeners : { 32 checkchange : function(node, checked, eOpts) { 33 // setChildChecked(node, checked); 34 if(node.isNode){ 35 if(beforNode != null){//把上一次选中节点取消选择,实现单选 36 beforNode.set("checked",false); 37 } 38 beforNode = node; 39 // node.collapse(); 40 // node.cascadeBy(function(node) { 41 // node.set("checked",checked); 42 // }); 43 } 44 } 45 } 46 }); 47 48 function setChildChecked(node, checked){ 49 node.set({checked:checked}); 50 if(node.hasChildNodes()){ 51 node.eachChild(function(child) { 52 setChildChecked(child, checked); 53 }); 54 } 55 } 56 57 function setParentChecked(node, checked){ 58 node.set({checked:checked}); 59 var parentNode = node.parentNode; 60 if(parentNode != null){ 61 var flag = false; 62 parentNode.eachChild(function(child) { 63 if(child.data.checked == true){ 64 flag = true; 65 } 66 }); 67 if (checked == false) { 68 if(!flag){ 69 setParentChecked(parentNode, checked); 70 } 71 } else { 72 if(flag){ 73 setParentChecked(parentNode, checked); 74 } 75 } 76 } 77 } 78 79 productCategoryLookUpWindow = Ext.create('Ext.window.Window', { 80 title : '产品分类信息', 81 autoShow: true, 82 width : 400, 83 constrain : true, 84 constrainHeader : true, 85 maximizable : false, 86 minimizable : false, 87 resizable : false, 88 closable : false, 89 buttonAlign : 'right', 90 animateTarget: Ext.getBody(), 91 modal : true, 92 plain : true, 93 border : true, 94 closeAction : 'destroy', 95 items : [productCategoryTreeMenu], 96 buttons : [{ 97 text : '确定', 98 handler : function() { 99 var checkNodeArray = productCategoryTreeMenu.getChecked(); 100 var checkNodeString = ''; 101 var checkNodeTextString = ''; 102 for (var index = 0; index < checkNodeArray.length; index++) { 103 checkNodeString += checkNodeArray[0].data.id; 104 checkNodeTextString += checkNodeArray[0].data.qtip; 105 } 106 if (Ext.isFunction(callback)) { 107 callback(checkNodeString, checkNodeTextString); 108 } 109 productCategoryLookUpWindow.destroy(); 110 } 111 }, { 112 text : '关闭', 113 handler : function() { 114 productCategoryLookUpWindow.destroy(); 115 } 116 }] 117 }); 118 119 } 120 121 productCategoryLookUpWindow.show(); 122 123 };
Java
for (ProductCategoryVO dbVo : productCategoryVOList) { JSONObject obj = new JSONObject(); obj.put("id", dbVo.getCategoryIdFull()); obj.put("text", dbVo.getCategoryName()); obj.put("qtip", dbVo.getCategoryNameFull()); obj.put("leaf", !new Boolean(dbVo.getIsExistChildNode())); obj.put("checked", new Boolean(false)); // obj.put("isExistChildNode", new Boolean(dbVo.getIsExistChildNode())); // obj.put("categoryId", dbVo.getCategoryId()); // obj.put("categoryName", dbVo.getCategoryName()); // obj.put("categoryIdFull", dbVo.getCategoryIdFull()); // obj.put("categoryNameFull", dbVo.getCategoryNameFull()); // obj.put("parentIdFull", dbVo.getParentIdFull()); // obj.put("parentNameFull", dbVo.getParentNameFull()); // obj.put("recordId", dbVo.getId()); // obj.put("nodeLevel", dbVo.getNodeLevel()); jsonArray.add(obj); }