1

我是 ExtJs 4 的新手。我正在使用 Json 填充组合框,如下所示,

JSON:

{
   "Patient": [
      {
         "id": 1,
         "emergencyPhone": "1234567890",
         "primaryInsuranceId": {
            "id": 1
         },
         "secondaryInsuranceId": {
            "id": 2
         },
         "personalInfo": {
            "id": 2,
            "firstName": "James",
            "lastName": "Anderson",
            "address": {
               "state": {
                  "id": "2",
                  "stateName": "Alaska",
                  "code": "AK"
               },
               "zipcode": 12345,
               "country": "USA",
               "telephone": "1234567890",
               "alternatePhone": "1234567890",
               "faxNumber": "1234567890",
               "email": "james@gmail.com"
            },
            "gender": "Male",
            "dob": "2012-04-02",
            "ssn": 123456789,
            "race": "race"
         },
         "clearinghouseId": {
            "id": 2,
            "name": "ALPHA Clearing House"
         },
         "provider": []
      }
   ]
}

代码:

Ext.define('patientList', {
    extend: 'Ext.data.Model',
    fields: ['id', 'personalInfo']
});

var patient = Ext.create('Ext.data.Store', {
    model: 'patientList',
    autoLoad: true,
    proxy: {
        type: 'ajax',
        url: url + '/lochweb/loch/patient/getAll',
        reader: {
            type: 'json',
            root: 'Patient'
        }
    }
});

组合框

{
    xtype: 'combo',
    fieldLabel: 'Patient',
    name: "patientId",
    id: "patientId",
    queryMode: 'local',
    store: patient,
    displayField: 'personalInfo.firstName',
    valueField: 'id',
    emptyText: "Select",
    editable: false,
    allowBlank: false
}

当我单击组合框时,它显示名字,但选择后,它没有显示在下拉列表中。任何帮助

谢谢

4

1 回答 1

2

像这样更改您的模型

Ext.define('patientList', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'myId', mapping: 'personalInfo.id' },
        { name: 'myFirstName', mapping: 'personalInfo.firstName' }
    ]
});

然后像这样改变你的组合

{
    xtype: 'combo',
    fieldLabel: 'Patient',
    name: "patientId",
    id: "patientId",
    queryMode: 'local',
    store: patient,
    displayField: 'myFirstName',  // Change This
    valueField: 'myId',           // Change This
    emptyText: "Select",
    editable: false,
    allowBlank: false
}

阅读有关映射转换配置的更多信息。

于 2012-04-27T18:17:26.187 回答