tree.loader.on('beforeload',function(treeLoader,node)带参数主要加了这个 事件
Ext.onReady(function(){ Ext.BLANK_IMAGE_URL = "ext/resources/images/default/s.gif"; var jobstore = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({url: "carservice/gw!jobAll.action"}), reader: new Ext.data.JsonReader({ root: 'root' },[ {name: 'jobid'}, {name: 'jobname'} ]) }); jobstore.load(); var job=new Ext.form.ComboBox({//下拉框 hiddenName:'job', fieldLabel:'车型', triggerAction:'all', // 单击触发按钮显示全部数据 store:jobstore, //设置数据源 displayField:'jobname', //定义要显示的字段 valueField:'jobid', //定义值字段 mode:'local', //本地模式 forceSelection:true, //要求输入值必须在列表中存在 resizable:true //允许改变下拉列表的大小 }) var form=new Ext.form.FormPanel({ title:'岗位权限分配', renderTo:'form', // region:'north', autoWidth:true, height:80, collapsible: true, autoScroll: true, labelAlign:'right',//标签对齐方式 frame:true, items:[{ layout:'column', items:[ {columnWidth:.50,layout:'form',items:[job]}, {columnWidth:.50,layout:'form',items:[{xtype:'button',width:50,text:'确认'}]}//,handler:onSelectClick ] }] }); var Tree = Ext.tree; var tree = new Tree.TreePanel({ el:'tree', // region:'center', useArrows:true, autoScroll:true, rootVisible:true,//是否显示根节点 animate:true, enableDD:true, containerScroll: true, loader: new Tree.TreeLoader({ dataUrl:'carservice/Power!Powertree.action' }), buttons:[{text:'选中的结果',handler:Oksubmit}] }); tree.loader.on('beforeload',function(treeLoader,node){ //带参数 this.baseParams.jobid =''+job.getValue() ; }); tree.on('checkchange', function(node, checked) { node.attributes.checked = checked; if(!node.isLeaf) { node.expand(); }else { node.eachChild(function(child) { child.ui.toggleCheck(checked); child.attributes.checked = checked; child.fireEvent('checkchange', child, checked); }); } if(node.getDepth()!=1) { var parentNode = node.parentNode; var b=false; var childNodes = parentNode.childNodes; if (childNodes && childNodes.length > 0) { for (var i = 0, len = childNodes.length; i < len; i++) { if(childNodes[i].getUI().checkbox){ b=childNodes[i].getUI().checkbox.checked; if(b) { break; } } } } nodeParCheckChange(node,b); } }, tree); // 当选择节点时影响所有的父节点 var nodeParCheckChange = function(node, bool) { if (node) { // 对所有的父节点进行选中与取消 var parentNode = node.parentNode; while (parentNode) { if(parentNode.getUI().checkbox){ parentNode.getUI().checkbox.checked = bool; } parentNode = parentNode.parentNode; } } }; function Oksubmit() { var checkedNodes = tree.getChecked();//tree必须事先创建好. var s = []; for(var i=0;i<checkedNodes.length;i++){ s.push(checkedNodes[i].id) } var data=Ext.encode(s); alert(data); } var root = new Tree.AsyncTreeNode({ text: '权限分配', draggable:false, jobid:'',//为了带这个参数设定与上面 tree的 beforeload 那个参数有关系 // checked:false, id:' ' }); tree.setRootNode(root); tree.render(); // root.expand(); // var portview=new Ext.Viewport({ // layout:'border', // items:[form,tree] // }); });