javascript - 如何根据 json 数据设置 radiogroup radiofield extjs 4

标签 javascript extjs extjs4

嗨,论坛成员,我在 extjs 4 中设置 radio 场时遇到了一个问题

下面给出了我的表单 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
  }]
}

我的员工 ListView 有执行以下功能的操作列 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 View 。我的编辑 Employee 正确显示了所有值,但只有 radio 场有问题。他们没有显示选定的值。

我提供给您的 json 数据是员工数据

我无法根据从 json 收到的数据设置广播组性别。

请给我一些解决方案。

最佳答案

首先,您应该将 inputValue 设置为“false”和“true”。第二个是radiogroup的新设计。您将在我的 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);
}  

关于javascript - 如何根据 json 数据设置 radiogroup radiofield extjs 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9942493/

相关文章:

javascript - 选择一个有效的选择。 '"xxx”不是可用选项之一

sorting - ExtJs 网格中可排序为 false 后列标题显示箭头图标

javascript - 如何在 ExtJS 中滚动到表单末尾

javascript - 选项卡/垂直框布局

ExtJS 应用程序事件问题

javascript - Uncaught Error : [Ext. 创建] 无法识别的类名/别名 : MyApp. store.LibraryFolderTreeStore

javascript - 如何在网格中的渲染器中获取当前渲染值?

javascript - 应用 ButtonSet 后禁用单个复选框

javascript - 显示其他两个输入值之和的输入框

javascript - 网站加载时可以从确定的 div 开始吗?