数据 只有第一个的
[ { "id": "1", "text": "Settings", "children": [ { "id": "5", "text": "User settings", "children": [ { "id": "6", "text": "Personal information", "children": [ { "id": "6_[view]", "text": "[view]", "children": [], "checked": true, "expanded": true, "disabled": false } ], "checked": true, "expanded": true, "disabled": false }, { "id": "7", "text": "Change password", "children": [ { "id": "7_[view]", "text": "[view]", "children": [], "checked": true, "expanded": true, "disabled": false } ], "checked": true, "expanded": true, "disabled": false }, { "id": "8", "text": "Login account management", "children": [ { "id": "8_[view]", "text": "[view]", "children": [], "checked": true, "expanded": true, "disabled": false } ], "checked": true, "expanded": true, "disabled": false } ], "checked": true, "expanded": true, "disabled": false }, { "id": "12", "text": "Transaction settings", "children": [ { "id": "13", "text": "Access website", "children": [ { "id": "13_[view]", "text": "[view]", "children": [], "checked": true, "expanded": true, "disabled": false } ], "checked": true, "expanded": true, "disabled": false }, { "id": "14", "text": "Trade password", "children": [ { "id": "14_[view]", "text": "[view]", "children": [], "checked": true, "expanded": true, "disabled": false } ], "checked": true, "expanded": true, "disabled": false }, { "id": "15", "text": "Transaction certificate", "children": [ { "id": "15_[view]", "text": "[view]", "children": [], "checked": true, "expanded": true, "disabled": false } ], "checked": true, "expanded": true, "disabled": false } ], "checked": true, "expanded": true, "disabled": false } ], "checked": true, "expanded": true, "disabled": false },
操作伸缩的代码
function CheckChild(node, checked) { //选择所有子节点 node.eachChild(function (child) { child.set("checked", checked); CheckChild(child, checked); }); } //选择所有父节点 function CheckParent(node, checked) { if (node.parentNode) { if (checked == true) { node.parentNode.set("checked", checked); CheckParent(node.parentNode, checked) return; } var ist = true; node.parentNode.eachChild(function (child) { if (child.get("checked") != false) ist = false; }); if (ist) { node.parentNode.set("checked", checked); CheckParent(node.parentNode, checked) } } }
var store = Ext.create('Ext.data.TreeStore', { proxy: { type: 'ajax', url: "../Handler/MEEmployee.ashx?method=QUERYPERMISSION&MEMPLOYEEID=" + m_EmployeeID }, root: { text: '<% = GetLocalResourceObject("AllPrivilegesText") %>', id: 'root', expanded: true, expandable: true, leaf: false } }); var tree = Ext.create('Ext.tree.Panel', { store: store, title: '<% = GetLocalResourceObject("PleasePermissionsText") %>', id: "treePermission", border: false, renderTo: "dvPermission", useArrows: true, height: 205, autoScroll: true, animate: true, enableDD: true, containerScroll: true }); tree.on('itemclick', function (view, record, item, index, event, eOpts) { var expand = record.get('expanded') if (expand) { view.collapse(record); } else { view.expand(record); } var checked = record.get("checked"); record.set("checked", !checked); CheckChild(record, !checked); CheckParent(record, !checked); }, tree); tree.getRootNode().expand();
传送id数据
function btnChange_OnClick() { var arrParams = ""; var nodes = tree.getChecked(); for (var i = 0; i < nodes.length; i++) { var id = nodes[i].get("id"); if (id != "root") arrParams += (',' + id); } //绑定界面数据 Ext.Ajax.request ({ url: "../Handler/MEEmployee.ashx", //添加 url 具体在哪个页面实现编辑修改功能 params: { "method": "EDITUSERPERMISSION", "USERID": m_EmployeeID, "USERPERMISSION": arrParams }, success: function (respose, option) { var result = Ext.JSON.decode(respose.responseText); if (result.Flag) { Ext.Msg.alert('<% = GetLocalResourceObject("UpdateSuccessText") %>', '<% = GetLocalResourceObject("PromptText") %>', Window_OnClose); } else { Ext.Msg.alert('<% = GetLocalResourceObject("FailText") %>', '<% = GetLocalResourceObject("SelectLessOneText") %>'); } }, failure: function () { //如果在服务器端处理数据发生了异常,就执行该函数的语句 Ext.Msg.alert('<% = GetLocalResourceObject("WrongText") %>', '<%= GetGlobalResourceObject("GlobalResource","Systemerror")%>'); } }); }