【问题标题】:how to set radiogroup radiofield based on the json data extjs 4如何根据json数据extjs 4设置radiogroup radiofield
【发布时间】:2012-03-30 11:58:39
【问题描述】:

您好论坛成员我在 extjs 4 中设置无线电场时遇到一个问题

我的表单 radiogroup xtype 代码如下

{
  xtype: 'radiogroup',
  dataIndex: 'gender',
  margin: 5,
  fieldLabel: 'Gender',
  items: [{
    xtype: 'radiofield',
    name: 'gender',
    boxLabel: 'Male',
    inputValue:'0'
  }, {
    xtype: 'radiofield',
    name: 'gender',
    boxLabel: 'Female',
    inputValue:'1'
  }]
}

我收到的 json 数据是

{
  "total": 1,
  "success": true,
  "employeedata": [{
     "username": "yaryan997",
     "surname": "Singh",        
     "firstname": "Yogendra",
     "gender": false
  }]
}

我的员工列表视图具有执行以下功能的操作列 editEmployee

editEmployee:function(grid,no,rowindex,colindex,temp) {
        alert('Edit EMPLOYEE button pressed');
        var rec = grid.store.getAt(rowindex);
        var employeeid = rec.get('id');

        store = grid.getStore();
        store.load({
            params: {'employeeid':employeeid},
            scope: this,
            callback: function(records, operation, success) {
                //the operation object contains all of the details of the load operation
                console.log(records);
                this.getEmployeeEdit().editform=1;
                this.getEmployeeEditForm().loadRecord(rec);                 
                this.getEmployeeEdit().show();
            }
        });
        this.getEmployeeStore().load();
    },

根据 id 显示 editEmployee 视图。我的编辑员工正确显示了所有值,但唯一的问题是无线电场。他们没有显示选定的值。

我提供给您的 json 数据,以员工数据的形式出现

我无法根据从 json 接收到的数据设置无线电组性别。

请给我一些解决方案。

【问题讨论】:

  • 您的收音机 inputValues 是字符串,您的 json 中“性别”的数据类型是 bool。也许那里有问题?

标签: javascript extjs extjs4


【解决方案1】:

首先您应该将inputValue 设置为“false”和“true”。第二个是无线电组的新设计。您将在我的 sencha 论坛的帖子中找到解决方案,请参阅:http://www.sencha.com/forum/showthread.php?187185-Set-a-int-value-on-a-radiogroup-fails&goto=newpost

问题是setValue 期待一个对象,只有当您必须为性别进行数据类型时才会出现这种情况;一个是男性,一个是女性......这就是我将其发布为错误的原因。从我的帖子中删除覆盖代码。

setValue: function (value) {
    if (!Ext.isObject(value)) {
        var obj = new Object();
        obj[this.name] = value;
        value = obj;
    }
    Ext.form.RadioGroup.prototype.setValue.call(this, value);
}  

【讨论】:

    【解决方案2】:

    实际上,问题在于您试图将布尔值传递给您的radioBox

    "gender": false
    

    你不应该这样做。

    如果将 true/false 值传递给其 setValue 方法,则 radioBox 将设置为选中/未选中,而忽略 inputValue 字段设置的内容。

    这里是源代码,我们可以看到传入的任何其他值最终都会以带有布尔参数的递归调用结束:

    setValue: function(v) {
        var me = this,
            active;
    
        if (Ext.isBoolean(v)) {
            me.callParent(arguments);
        } else {
            active = me.getManager().getWithValue(me.name, v, me.getFormId()).getAt(0);
            if (active) {
                active.setValue(true);
            }
        }
        return me;
    }
    

    【讨论】:

      猜你喜欢
      • 2013-02-03
      • 1970-01-01
      • 1970-01-01
      • 2016-09-08
      • 1970-01-01
      • 1970-01-01
      • 2017-07-17
      • 2011-08-19
      • 2012-05-10
      相关资源
      最近更新 更多