问题描述
这是树的代码 我想用下面的代码来获得选中的idvar b = Ext.tree.getChecked();var check = new Array();for (var i = 0; i < b.length; i++) {check.push(b[i].id);}for (var i = 0; i < check.length; i++) {Ext.DomHelper.append('form1',{tag:'input',name:'checks',type:'hidden',value:check[i]})}//把获得的id通过form提交到action 上面这些代码 应该放到什么地方?Ext.onReady(function() {Ext.BLANK_IMAGE_URL = "/dtjcsy/pages/js/ext/resources/images/default/s.gif";var Tree= Ext.tree;var form =Ext.get('form1');var loader = new Ext.tree.TreeLoader;var tree = new Tree.TreePanel({el:'tree-div', autoScroll:true, animate:true, enableDD:true, frame:false, border:false, useArrows:true, checkModel:'cascade', onlyLeafCheckable:false, rootVisible:true, bodyStyle:'background-color:#b4d5f5', containerScroll: true,loader: new Tree.TreeLoader({dataUrl:'rightAction.action',baseParams:{roleId:2},baseAttrs: { uiProvider: Ext.ux.TreeCheckNodeUI }}),listeners:{load:function(loader,node,response){}, checkchange:function(node,checked){ } }});var root =new Tree.AsyncTreeNode({text:"可用权限列表",draggable:false,id:'0'});tree.setRootNode(root);tree.render();root.expand(true);}); 问题补充:myali88 写道
解决方案
哦,有点问题,把form.submit = function() { 改成form.dom.submit = function() {
解决方案二:
var form = Ext.get('form1'); 你页面上有没有id为“form1”的form标签啊?
解决方案三:
Ext.BLANK_IMAGE_URL = "/dtjcsy/pages/js/ext/resources/images/default/s.gif";Ext.onReady(function() {var tree = new Tree.TreePanel({renderTo:'tree-div', autoScroll:true, animate:true, enableDD:true, frame:false, border:false, useArrows:true, checkModel:'cascade', onlyLeafCheckable:false, rootVisible:true, bodyStyle:'background-color:#b4d5f5', containerScroll: true,loader: new Tree.TreeLoader({dataUrl:'rightAction.action',baseParams:{roleId:2},baseAttrs: { uiProvider: Ext.ux.TreeCheckNodeUI }}),root : new Tree.AsyncTreeNode({text:"可用权限列表",draggable:false,id:'0'})});var form = Ext.get('form1');form.submit = function() {var ids = tree.getChecked('id') , len = ids.length; for (var i = 0; i < len ; i++) {Ext.DomHelper.append('form1',{tag:'input',name:'checks',type:'hidden',value:ids[i]})}}});这样应该就可以了。
解决方案四:
Ext.BLANK_IMAGE_URL = "/dtjcsy/pages/js/ext/resources/images/default/s.gif";Ext.onReady(function() {var tree = new Tree.TreePanel({renderTo:'tree-div', autoScroll:true, animate:true, enableDD:true, frame:false, border:false, useArrows:true, checkModel:'cascade', onlyLeafCheckable:false, rootVisible:true, bodyStyle:'background-color:#b4d5f5', containerScroll: true,loader: new Tree.TreeLoader({dataUrl:'rightAction.action',baseParams:{roleId:2},baseAttrs: { uiProvider: Ext.ux.TreeCheckNodeUI }}),root : new Tree.AsyncTreeNode({text:"可用权限列表",draggable:false,id:'0'})});var form = Ext.get('form1');form.submit = function() {var ids = tree.getChecked('id') , len = ids.length; for (var i = 0; i < len ; i++) {Ext.DomHelper.append('form1',{tag:'input',name:'checks',type:'hidden',value:ids[i]})}}});这样应该就可以了。
解决方案五:
这样调用肯定不对,我是直接按你写的来的,具体getChecked方法的调用要在Tree实例上调用:var tree = new Tree.TreePanel({ //...tree.getChecked('id')
解决方案六:
<form onsubmit="return beforeSubmit()"> 标签里面加上onsubmit 把代码放到beforeSubmit的函数里面 最后return true
解决方案七:
引用我只是用了ext的树 别的都不是ext的 这个树放在页面的一个form里 我想提交form 的时候把节点id也提交了 我知道,那你就可以在提交form前调用你上面的那段代码。通过监听submit事件完成。
解决方案八:
引用把获得的id通过form提交到action 上面这些代码 应该放到什么地方? 看你什么时候触发提交form,在哪里触发就在哪里执行上面那段代码。另外,根据getChecked方法的说明,如果要直接获取node上的某个属性,可以直接这样:Ext.tree.getChecked('id'); //返回的数组就是包含id的值,你可以获取其他的值,避免你自己由迭代一次