Results 1 to 6 of 6

Thread: Binding combobox to a inner object

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Jun 2012
    Posts
    16
    Vote Rating
    0
      0  

    Default Binding combobox to a inner object

    Hi, this is my json from server:
    Code:
    [
      {
        "consulta_id": 23752, 
        "convenio_id": 1, 
        "data": "2012-07-11", 
        "id": 36569, 
        "paciente": {
          "nome": "Alvasole", 
          "id": 12
        }, 
        "tipo": 1
      }, 
      {
        "consulta_id": 23753, 
        "convenio_id": 61, 
        "data": "2012-07-11", 
    	"id": 36579,
        "paciente": {
          "nome": "Felintoi", 
          "id": 33
        }, 
        "tipo": 1
      }
    ]
    
    
    I need to bind the combobox to the field: paciente.id and paciente.nome, respectively to valueField and displayField.

    This combo will only have 1 record on its store.

    I get this work in this way:

    Code:
        this.getForm().loadRecord(rec);
        combo.store = Ext.create('Ext.data.Store', {
                fields: ['id', 'nome'],
                data : [
                    rec.get('paciente')
                ]
            });
    But i think that may have a better way.

  2. #2
    Sencha User Legolas's Avatar
    Join Date
    Apr 2010
    Location
    Brazil/MG
    Posts
    58
    Vote Rating
    4
      0  

    Default

    Hi larini,

    You may use a Model for your Store and in your fields you use the mapping property. Like below:
    Code:
    Ext.define('ModelName', {
         extend: 'Ext.data.Model'
        ,fields: [
            {name: 'id',  type: 'int', mapping: 'paciente.id'},
            {name: 'age',   type: 'int', convert: null},
            {name: 'phone', type: 'string'},
            {name: 'alive', type: 'boolean', defaultValue: true, convert: null}
        ]
    });
    
    
    var store = Ext.create('Ext.data.Store', {
           model: 'ModelName'
          ,autoLoad: true
          ,proxy: {
             type: 'ajax'
            ,url: 'page.php' // Define your PHP file
            ,reader: {
               type: 'json'
              ,root: 'root'
            }
         }     
     });
    I am sorry my english, I am learning yet
    Portuguese blog: http://wessdevel.blogspot.com.br/
    Twitter: @wlegolas

  3. #3
    Sencha User
    Join Date
    Jun 2012
    Posts
    16
    Vote Rating
    0
      0  

    Default

    I already tried this, but is not working. It looks like there must be a stored already defined in the combobox. How I must declare the combobox control ?

  4. #4
    Sencha User Legolas's Avatar
    Join Date
    Apr 2010
    Location
    Brazil/MG
    Posts
    58
    Vote Rating
    4
      0  

    Default

    It looks like there must be a stored already defined in the combobox
    The Store of combobox should be defined when you create him. Set your Model, Store and after set your ComboBox with the Store equal my example.
    I am sorry my english, I am learning yet
    Portuguese blog: http://wessdevel.blogspot.com.br/
    Twitter: @wlegolas

  5. #5
    Sencha User
    Join Date
    Jun 2012
    Posts
    16
    Vote Rating
    0
      0  

    Default

    Ok, but I thought that was an automatic way to do that. Something that runs after a form load and fills the store automatically.

  6. #6
    Sencha User Legolas's Avatar
    Join Date
    Apr 2010
    Location
    Brazil/MG
    Posts
    58
    Vote Rating
    4
      0  

    Default

    Hi larini,

    If I understand right, you are editing a record and the value in your ComboBox not being selected. So yor doubt is "How do I select a value in the registry editing in Combo?". It would this your question?
    Would have like to post the code of your ComboBox and your Store?
    I am sorry my english, I am learning yet
    Portuguese blog: http://wessdevel.blogspot.com.br/
    Twitter: @wlegolas

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •