ExtJS4中的Json解析

ExtJS4中的Json解析,extjs4,Extjs4,我是ExtJS4新手。我使用Json填充组合框,如下所示 JSON: {    "Patient": [       {          "id": 1,          "emergencyPhone": "1234567890",          "primaryInsuranceId": {             "id": 1          },          "secondaryInsuranceId": {             "id": 2          }

我是ExtJS4新手。我使用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'
        }
    }
});
代码:

{
   "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
}
当我单击组合框时,它会显示firstname,但选择该组合框后,它不会显示在下拉列表中。是否有帮助


谢谢

像这样更改您的型号

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
}
然后像这样更改您的组合:

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
}

阅读更多关于和配置的信息。

您的Json对于组合数据的格式不正确。除此之外,我在您的Json中没有找到任何“Patient”根。检查这个例子:谢谢你的评论,我已经编辑了这个问题,json是清楚的。有没有关于在组合框中填充json的帮助,Natasha,有没有关于填充组合框的帮助