+ -
当前位置:首页 → 问答吧 → 急!!!!!!!!!新手关于EXTJS动态赋值的问题

急!!!!!!!!!新手关于EXTJS动态赋值的问题

时间:2011-08-11

来源:互联网

代码片段如下:

var StudentRecord = Ext.data.Record.create([
  {name: 'id',type: 'string'}, // 客户类别ID
  {name: 'bizname',type: 'string'}, // 客户类别ID
  {name: 'bizvalue',type: 'string'}, // 客户类别ID
  {name: 'attr0',type: 'string'}, // 客户类别ID
  {name: 'attr1',type: 'string'}, // 客户类别名称
  {name: 'valuetext',type: 'string'}, // 客户类别名称
  ]); ....省略



var mod_form = new Ext.FormPanel({
  labelWidth: 80,
  labelAlign: 'right',
  frame: true,
  defaults: {
  width: 160
  },
  bodyStyle: 'padding:10px 5px 0',
  defaultType: 'textfield',
  monitorValid: true,
  items: [
  {
  id: 'id',
  name: 'id',
  hidden: true
  },{
  id: 'bizname',
  fieldLabel: '业务名称',
  name: 'bizname',
  disabled: true
  },{
  id: 'valuetext',
  fieldLabel: '当前设定',
  name: 'valuetext',
  maxLength:20
  },
  {  
  xtype:'radiogroup',  
  id : 'valuetext',  
  name : 'valuetext',  
  width: 150,  
  fieldLabel:'业务设定',  
  items : [  
  {name:'aa' ,boxLabel:'1' ,xtype:'radio', inputValue: 0,checked: true },  
  {name:'aa' ,boxLabel:'2' ,xtype:'radio', inputValue: 1 }  
  ]}

  ],...后面省略

问题1:请问如何通过代码为radiogroup中两个单选框选项中的boxLabel属性赋值,比如说现在boxlabel的值是1和2,我想通过代码让这个两个单选按钮的boxlabel显示3和4?

问题2: 根据record中的绑定好的项 bizvalue进行判断,如果bizvalue的值是0,则单选按钮的第一项被设置成默认选中,如果是1则单选按钮的第二个选项被选中,这个判断的JS脚本应该在怎样写呢

作者: xiao_yao80910   发布时间: 2011-08-11

JScript code
{
        xtype : 'radiogroup',
        id : 'valuetext',
        name : 'valuetext',
        width : 150,
        fieldLabel : '业务设定',
        items : [{
            name : 'aa',
            id:'radiao1',
            boxLabel : '1',
            xtype : 'radio',
            inputValue : 0
            
        }, {
            name : 'aa',
            id:'radiao2',//增加id
            boxLabel : '2',
            xtype : 'radio',
            inputValue : 1
        }],
        listeners :{
              'render':function(){
                            //问题2解决方案 在渲染时做赋值操作
                 var bizVal = record.get('bizvalue');
                    if(bizVal == 0){
                        Ext.getCmp('radiao1').setValue(true);
                    }else{
                       Ext.getCmp('radiao2').setValue(true);
                    }
              }
            }
    }
问题1解决方案:
这个需求Ext没有相应的方法 通常我们借助Ext的DomQuery来操作元素 
这个问题相对简单点 还不需要DomQuery
JScript code
document.getElementById('radio1').nextSibling.innerHTML = 3;
document.getElementById('radio2').nextSibling.innerHTML = 4;


作者: fanchuanzhidu   发布时间: 2011-08-11

晕死~~ 上边问题1解决方案中的id写错了 应该是'radiao1' 和'radiao2'

作者: fanchuanzhidu   发布时间: 2011-08-11