[Form] 后台取数据控制Chekbox的选定

[ 336 查看 / 9 回复 ] 相关帖子

后台取数据控制Chekbox的选定

大家好,我是新手,刚用extjs,遇到一个问题,怎么从后台获取数据来控制复选框的选定情况呢?
以及如何将所有复选框的信息传到后台呢?
分享 转发
TOP

后台取数据控制Chekbox的选定

可以为checkbox添加inputValue用于传送的值,和写个id,后台接受就Request["id"],就是inputValue的值,如果没打勾就不传相应的id.
TOP

后台取数据控制Chekbox的选定

回复 2# noriri 的帖子

我是chekboxground啊 就是数据库里面 把所有选中的都得传过去 然后好像每个chekbox里面也没有写id啊 只写了一个名字
TOP

后台取数据控制Chekbox的选定

默认的是cb-auto-1,可以用name属性换你要的,你可以用Request["cb-auto-1"]取,打勾的是on,反之。也可以用inputValue定义
其实你可以下载个Fiddler或者用FireBUg一看就知道传送的是什么了
最后编辑noriri 最后编辑于 2010-03-15 09:09:49
TOP

后台取数据控制Chekbox的选定

回复 4# noriri 的帖子

我为什么传送的都是 [object object]啊 没有值
TOP

后台取数据控制Chekbox的选定

回复 4# noriri 的帖子

传到后台是把name的值传到后台吗
TOP

后台取数据控制Chekbox的选定

是个,再不行的话,上点代码看看么。
TOP

后台取数据控制Chekbox的选定

回复 7# noriri 的帖子

{
            fieldLabel: kernel.bundle.getMsg('Filter state'),
            id: 'filter_country',
            xtype:'checkboxgroup',
            columns: 3,
                items:[
                {boxLabel:kernel.bundle.getMsg('AU'), name: 'filter_country',inputValue:'AU'},
                {boxLabel:kernel.bundle.getMsg('BY'), name: 'filter_country',inputValue:'BY'},
                {boxLabel:kernel.bundle.getMsg('BE'), name: 'filter_country',inputValue:'BE'},
                {boxLabel:kernel.bundle.getMsg('DK'), name: 'filter_country',inputValue:'DK'},
                {boxLabel:kernel.bundle.getMsg('DE'), name: 'filter_country',inputValue:'DE'},
                {boxLabel:kernel.bundle.getMsg('RU'), name: 'filter_country',inputValue:'RU'},
                {boxLabel:kernel.bundle.getMsg('FR'), name: 'filter_country',inputValue:'FR'},
                {boxLabel:kernel.bundle.getMsg('FI'), name: 'filter_country',inputValue:'FI'},
                {boxLabel:kernel.bundle.getMsg('KR'), name: 'filter_country',inputValue:'KR'},
                {boxLabel:kernel.bundle.getMsg('NL'), name: 'filter_country',inputValue:'NL'},
               {boxLabel:kernel.bundle.getMsg('PL'), name: 'filter_country',inputValue:'PL'},
               {boxLabel:kernel.bundle.getMsg('CA'), name: 'filter_country',inputValue:'CA'},
                {boxLabel:kernel.bundle.getMsg('US'), name: 'filter_country',inputValue:'US'},
                {boxLabel:kernel.bundle.getMsg('NO'), name: 'filter_country',inputValue:'NO'},
                {boxLabel:kernel.bundle.getMsg('JP'), name: 'filter_country',inputValue:'JP'},
                {boxLabel:kernel.bundle.getMsg('SE'), name: 'filter_country',inputValue:'SE'},
                {boxLabel:kernel.bundle.getMsg('CH'), name: 'filter_country',inputValue:'CH'},
                {boxLabel:kernel.bundle.getMsg('UK'), name: 'filter_country',inputValue:'UK'},
                {boxLabel:kernel.bundle.getMsg('MO'), name: 'filter_country',inputValue:'MO'},
                {boxLabel:kernel.bundle.getMsg('TW'), name: 'filter_country',inputValue:'TW'}
             
           
             ]
        }这是chekboxgound的代码


所有数据的列表 this.itemList = [
    // ['id','id'],
     ['name','name'],
      ['team_name','team_name'],
      ['schedule_name','schedule_name'],
      ['filter_country','filter_country'],
      ['filter_type','filter_type']
   
    ];


获取所有数据的值
function aa(fs){
              var ret = '';
        var field = '';
        var j=0;
        for(var i=0; i<this.itemList.length;i++){
            var itemid = this.itemList[0];
            try{
                var itemvalue = fs.findById(itemid).getValue();
                if(ret == ''){
                    ret = this.itemList[1] + '=' + itemvalue;
                    field = this.itemList[1];
                    j++;
                }else{
                    ret = ret + '&' + this.itemList[1] + '=' + itemvalue;
                    field = field + ',' + this.itemList[1];
                    j++;
                }
            }catch (e){
                continue;
            }
        }
        return ret + '&byfield=' + field;}


传到后台'actiontype=4&generatetype=421&' +this.aa(fs);


列表其余的值都能得到 但是chekbox里面的数据得不到
我也不知道应该怎么传
TOP

后台取数据控制Chekbox的选定

chekboxground的getValue方法返回的是个已选项的数组,不是一个单一的值,因此,需要在获取值后判断是否为数组,如果是数组,还需要进一步进行组合以后才能得到需要的值,如:
  1. function aa(fs){
                  var ret = '';
            var field = '';
            var j=0;
            for(var i=0; i<this.itemList.length;i++){
                var itemid = this.itemList[0];
                try{
    var itemvalueobj=fs.findById(itemid).getValue();
                    var itemvalue = '';
    if(Ext.isArray(itemvalueobj)){
    //是数组,此处放循环处理的代码,形成字符串并给itemvalue赋值
    }else{
    itemvalue=itemvalueobj;
    }
                    if(ret == ''){
                        ret = this.itemList[1] + '=' + itemvalue;
                        field = this.itemList[1];
                        j++;
                    }else{
                        ret = ret + '&' + this.itemList[1] + '=' + itemvalue;
                        field = field + ',' + this.itemList[1];
                        j++;
                    }
                }catch (e){
                    continue;
                }
            }
            return ret + '&byfield=' + field;}
复制代码
TOP

后台取数据控制Chekbox的选定

如果是name都一样的话,直接用Request["filter_country"]取,多个的话自动用逗号分开
TOP