dontide 2009-08-31 10:47
浏览 296
已采纳

Ext JS checkbox 获得选中值

[code="java"]
/** **************************** 菜单权限管理 ***************************** */

// 菜单权限(form)
var _addPurviewMenuForm = new Ext.FormPanel({
    labelAlign : 'left',
    autoHeight : true,
    collapsible : true,
    width : 420,
    frame : true,
    title : '权限信息',
    bodyStyle : 'padding:5px',
    items : [{
        bodyStyle : 'padding:5px',
        layout : 'column',
        items : [{
            columnWidth : .2
        }, {
            baseCls : 'x-plain',
            columnWidth : .6,
            layout : 'form',
            labelWidth : 70,
            items : [{
                fieldLabel : '请选择用户',
                xtype : 'combo',
                mode : 'local',
                width : 145,
                triggerAction : 'all',
                store : userStore,
                valueField : 'id',
                displayField : 'name',
                emptyText : '请选择用户',
                editable : false,
                name : 'userinfo'
            }]
        }, {
            columnWidth : .2
        }]
    }, {
        xtype : 'fieldset',
        title : '选择菜单',
        // collapsible : true,
        width : 383,
        autoHeight : true,
        items : [{
            layout : 'column',
            defaults : {
                hideLabels : true,
                layout : 'form'
            },
            items : [{
                columnWidth : .01
            }, {
                columnWidth : .33,
                items : [new Ext.form.Checkbox({
                    boxLabel : '首页',
                    name : 'no',
                    inputValue : 1,
                    checked : true,
                    disabled : true
                })]
            }, {
                columnWidth : .33,
                items : [new Ext.form.Checkbox({
                    boxLabel : '实时监测',
                    name : 'no',
                    inputValue : 2,
                    checked : false
                })]
            }, {
                columnWidth : .33,
                items : [new Ext.form.Checkbox({
                    boxLabel : '历史查询',
                    name : 'no',
                    inputValue : 3,
                    checked : false
                })]
            }, {
                columnWidth : .01
            }, {
                columnWidth : .33,
                items : [new Ext.form.Checkbox({
                    boxLabel : '能耗分析',
                    name : 'no',
                    inputValue : 4,
                    checked : false
                })]
            }, {
                columnWidth : .33,
                items : [new Ext.form.Checkbox({
                    boxLabel : '用能诊断',
                    name : 'no',
                    inputValue : 5,
                    checked : false
                })]
            }, {
                columnWidth : .33,
                items : [new Ext.form.Checkbox({
                    boxLabel : '事件报警',
                    name : 'no',
                    inputValue : 6,
                    checked : false
                })]
            }, {
                columnWidth : .01
            }, {
                columnWidth : .33,
                items : [new Ext.form.Checkbox({
                    boxLabel : '数据录入',
                    name : 'no',
                    inputValue : 7,
                    checked : false
                })]
            }, {
                columnWidth : .33,
                items : [new Ext.form.Checkbox({
                    boxLabel : '统计报表',
                    name : 'no',
                    inputValue : 8,
                    checked : false
                })]
            }, {
                columnWidth : .33,
                items : [new Ext.form.Checkbox({
                    boxLabel : '设置管理',
                    name : 'no',
                    inputValue : 9,
                    checked : false
                })]
            }, {
                columnWidth : .01
            }, {
                columnWidth : .33,
                items : [new Ext.form.Checkbox({
                    boxLabel : '计费系统',
                    name : 'no',
                    inputValue : 10,
                    checked : false
                })]
            }, {
                columnWidth : .33,
                items : [new Ext.form.Checkbox({
                    boxLabel : '演示系统',
                    name : 'no',
                    inputValue : 11,
                    checked : true,
                    disabled : true
                })]
            }, {
                columnWidth : .33,
                items : [new Ext.form.Checkbox({
                    boxLabel : '风格',
                    name : 'no',
                    inputValue : 12,
                    checked : true,
                    disabled : true
                })]
            }]
        }]
    }]
});

// 菜单权限(window)
var newPurviewMenuWin;
function handlePurviewMenuWin() {
    if (!newPurviewMenuWin) {
        newPurviewMenuWin = new Ext.Window({
            applyTo : 'PurviewMenu_window',
            title : '菜单权限管理',
            layout : 'fit',
            closable : false,
            width : 420,
            height : 265,
            plain : true,
            items : _addPurviewMenuForm,
            buttons : [{
                text : '保存',
                handler : function() {
                    if (_addPurviewMenuForm.form.isValid()) {
                        _addPurviewMenuForm.form.submit({
                            url : '',
                            waitMsg : "正在提交表单数据,请稍

候......",
failure : function(form, action) {
newPurviewMenuWin.hide();
_addPurviewMenuForm.getForm

().reset();
}
});
} else {
Ext.Msg.alert('信息', '请填写完整在提交!');
}
}
}, {
text : '取消',
handler : function() {
_addPurviewMenuForm.getForm().reset();
newPurviewMenuWin.hide();
}
}]
});
}
newPurviewMenuWin.show(this);
}
[/code]
我有一个这个的权限设置form,form里面的复选按钮都是一个一个的创建,代码如上,我现在的需求是想点一下保存按钮后去得到上面form表单里面checkbox的选中值(可以选中多个值),麻烦大家帮我实现一下,我试了很久都没有试出来。谢谢了。图片如下:
[img]http://www.iteye.com/upload/attachment/141092/8a804ed8-1193-3eb7-b6aa-d49efd2c038f.jpg[/img]

  • 写回答

4条回答 默认 最新

  • iteye_10013 2009-08-31 15:00
    关注

    试下:

    [code="java"] // 菜单权限(form)
    var _addPurviewMenuForm = new Ext.FormPanel({
    labelAlign : 'left',
    autoHeight : true,
    collapsible : true,
    width : 420,
    frame : true,
    title : '权限信息',
    renderTo:Ext.getBody(),
    bodyStyle : 'padding:5px',
    items : [{
    bodyStyle : 'padding:5px',
    layout : 'column',
    buttons:[
    {
    text:'save',
    handler:function(){
    var cks = _addPurviewMenuForm.findByType('checkbox');
    for(var i=0;i<cks.length;i++){
    var ck = cks[i];
    if(ck.checked){
    console.log(ck.inputValue)
    }
    }
    }}
    ],
    items : [{
    columnWidth : .2
    },[/code]

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

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条