1

I am new to ExtJs 4.I am using Json to populate combo box,as follows,

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": "[email protected]"
            },
            "gender": "Male",
            "dob": "2012-04-02",
            "ssn": 123456789,
            "race": "race"
         },
         "clearinghouseId": {
            "id": 2,
            "name": "ALPHA Clearing House"
         },
         "provider": []
      }
   ]
}

Code:

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

Combo Box

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

When i click the combo box,it shows firstname but after selecting that,it is not displaying in drop down.Any Help

Thanks

3
  • Your Json is not well-formed for Combo data. Apart from that I didn't find any 'Patient' root in your Json. Check this example: docs.sencha.com/ext-js/4-0/#!/api/Ext.form.field.ComboBox Commented Apr 27, 2012 at 11:01
  • Thanks for comment,i have edited the question,nw the json are clear.any help abot hw to populate Json in combo box Commented Apr 27, 2012 at 12:06
  • Hi Natasha,Any help to populate combo box Commented Apr 27, 2012 at 12:30

1 Answer 1

2

Change your Model like this:

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

Then change your Combo like this:

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

Read more about Mapping and Convert configs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.