XX12555 2011-08-29 13:15
浏览 308
已采纳

form提交js变量

现在有个ext树 jsp页面如何提交树里的被选中的节点 check
[code="java"]
var check = [];

Ext.onReady(function() {

Ext.BLANK_IMAGE_URL = "/dtjcsy/pages/js/ext/resources/images/default/s.gif";

var Tree= Ext.tree;

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,   
    listeners:{   
        checkchange:function(node,checked){   
        if(checked){   
            var id = node.attributes.id;   
            check.push(id);   
        }   
        }   
    },   
    loader: new Tree.TreeLoader({   
        dataUrl:'rightAction.action',   
        baseParams:{roleId:1},   
        baseAttrs: { uiProvider: Ext.ux.TreeCheckNodeUI }   
    })   
});   

var root =new Tree.AsyncTreeNode({   
    text:"可用权限列表",   
    draggable:false,   
    id:'0'  
});   

tree.setRootNode(root);   
tree.render();   
root.expand();   

});

[/code]

jsp页面
[code="java"]
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <title>添加角色</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
    <link rel="stylesheet" type="text/css" href="../js/ext/resources/css/ext-all.css"/>
    <script type="text/javascript" src="../js/ext/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="../js/ext/ext-all.js"></script>
    <SCRIPT type="text/javascript" src="../js/TreeCheckNodeUI.js"></SCRIPT>
    <script type="text/javascript" src="exttree.js"></script>
    <style type="text/css">

<body>
    <form action="roleAction.action" id="form1" method="post">
    <input type="hidden" name="rwm.submitFlag" value="add">
    <input type="hidden" name="checks" id="checks" >
        <table width="100%" cellpadding="0" cellspacing="1">
            <tr>
                <td height="23px" background="/dtjcsy/pages/images/tab_05.gif"
                    width="100%">
                </td>
            </tr>
            <tr>
                <td>
                    <table width="100%" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <td height="15" width="100%"></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table width="618" border="0" cellpadding="2" cellspacing="1"
                        align="center" bgcolor="#333333" height="364">
                        <tr>
                            <td height="28" align="center" bgcolor="#b4d5f5">
                                添加角色信息
                            </td>
                        </tr>
                        <tr>
                            <td bgcolor="#b4d5f5">
                                <table width="100%" border="0" cellpadding="0" cellspacing="0"
                                    bgcolor="#b4d5f5">
                                    <tr>
                                        <td width="40%" bordercolor="#333333">
                                            <table width="40%" border="0" cellpadding="0"
                                                cellspacing="0" height="408" >
                                                <tr>
                                                <td valign="top">
                                                <table width="264" height="157">
                                                <tr>
                                                    <td class="STYLE6" >
                                                        角色名称:
                                                    </td>
                                                    <td class="td1">
                                                        <input type="text" name="tbr.rolename" border="0" class="input1" />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="STYLE6">
                                                        角色描述:
                                                    </td>
                                                    <td class="td1">
                                                        <textarea rows="4" cols="17" name="tbr.roledes"></textarea>
                                                    </td>
                                                </tr></table>
                                                </td></tr>
                                            </table>
                                        </td>
                                        <td  class="STYLE6">
                                            <table border="0" cellspacing="0" cellpadding="0"
                                                width="358" id="funTable" height="408" >

                                                <tr>
                                                    <td valign="top">
                                                        <div id="tree-div" style="overflow:auto; height:300px;width:250px;border:1px solid #c3daf9;">

                                                        </div>

                                                    </td>
                                                </tr>
                                            </table>

                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="4" align="center" bgcolor="#b4d5f5">
                                <input type="submit" value="确&nbsp;&nbsp;&nbsp;&nbsp;定" />
                                &nbsp;&nbsp;&nbsp;&nbsp;
                                <input type="reset" value="重&nbsp;&nbsp;&nbsp;&nbsp;置"
                                    onclick="form1.reset" />
                                &nbsp;&nbsp;&nbsp;&nbsp;
                                <input type="button" value="取&nbsp;&nbsp;&nbsp;&nbsp;消"
                                    onclick="top.document.all('right').src='/dtjcsy/pages/sys/RoleMsg.jsp'">
                            </td>

                        </tr>

                    </table>
                </td>
            </tr>

        </table>
    </form>
</body>

[/code]

  • 写回答

6条回答 默认 最新

  • myali88 2011-08-29 23:32
    关注

    [quote]
    我的意思 是 我选择了 然后 又取消了 结果是 取消后它还是传后台了

    [/quote]
    怎么会呢?[code="java"]
    if(checked){

    Ext.DomHelper.append('example-form' , {tag: 'input', name: 'id', type : 'hidden' , value: id});

    }else{

    var inputs = Ext.DomQuery.jsSelect('input[value=' + id + ']' , 'example-form');

    for(var i = 0 , len = inputs.length ; i < len ; i++) {

    form.dom.removeChild(inputs[i]);

    }

    }

    [/code]
    这一段的逻辑就是如果选中就在form里面增加相应的input,如果取消选择就从form里面把input删除,那么最终form里面只包含选中的节点对应的input,提交到服务器也是只保护选择的。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证