how to set radiogroup radiofield based on the json data extjs 4

岁酱吖の 提交于 2020-01-04 05:35:32

问题


hi forum member I am having one problem with setting the radiofield in the extjs 4

my form radiogroup xtype code is given below

{
  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'
  }]
}

my json data I am receiving is

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

my employee list view has action column editEmployee which executes the below function

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();
    },

based on the id the editEmployee view is shown. My edit Employee shows all the values correctly but only the problem is with the radiofield. They didn't show the selected value.

my json data I had provide you which comes as employeedata

I am not able to set the radiogroup gender based on the data i am receiving from the json.

please suggest me some solution for it.


回答1:


First you should set inputValue to 'false' and 'true'. The second is the new design of a radiogroup. You will find the solution in my thread at the sencha forum See: http://www.sencha.com/forum/showthread.php?187185-Set-a-int-value-on-a-radiogroup-fails&goto=newpost

The problem is that setValue is expecting a object which would only be the case if you had to datatypes for gender; one for male and one for female... And that's the point why I posted this as bug. Down the override code from my post.

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:


Actually, the problem is that you are trying to pass a boolean value to your radioBox:

"gender": false

which you are not supposed to.

The radioBox will be set to checked/unchecked if a true/false value is passed to its setValue method, ignoring what is the inputValue field set to.

Here is the source code, we can see that any other value passed in will finally end with a recursive call with boolean parameter:

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;
}


来源:https://stackoverflow.com/questions/9942493/how-to-set-radiogroup-radiofield-based-on-the-json-data-extjs-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!