1. #1
    Sencha User
    Join Date
    Aug 2012
    Posts
    6
    Vote Rating
    0
    nannuru is on a distinguished road

      0  

    Default Unanswered: How to define the Model and Load the store for this Complex Json

    Unanswered: How to define the Model and Load the store for this Complex Json


    {
    • field1: "value1",
    • field2: "value2",
    • field3: "value3",
    • field4: "value4",
    • field5: "value5",

    • -details: {
      • field6: "value6",
        • field7: "value7",
    • }
    • -
      adddetails: [
      • -
        {
        • field8: "value8",
          • field9: "value9",
      • }
      • -
        {
        • field8: "value10",
          • field9: "value11",
      • }
    • ]
    }

  2. #2
    crysfel's Avatar
    Join Date
    Feb 2008
    Location
    New York, USA
    Posts
    216
    Answers
    7
    Vote Rating
    8
    crysfel will become famous soon enough

      0  

    Default


    You can use the mapping property of the fields to specify the path from the value will be extracted.

    Code:
    Ext.define('MyApp.model.MyModel',{
       extend : 'Ext.data.Model',
    
       fields : [
          {name:'field6',mapping:'details.field6'},
          {name:'field7',mapping:'details.field7'}
       ]
    });
    For the array you can create a one-to-many association. You can find more information on the documentation: http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Model

    Regards

  3. #3
    Sencha User
    Join Date
    Aug 2012
    Posts
    6
    Vote Rating
    0
    nannuru is on a distinguished road

      0  

    Default


    Thanks for the reply .But in the store it is not getting the values.

  4. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,927
    Answers
    656
    Vote Rating
    443
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Your entries 'details' is an object and you 'adddetails' is an array
    Was this Intentional?

    so you would need to use:
    Code:
    { mapping:'adddetails[0].fieldx' }
    You can also use the qualifier in you field/data index when using objects

    Code:
    dataIndex: 'details.field6'
    fields:['details.field6'],
    If you need to separate.

    Scott.

  5. #5
    Sencha User
    Join Date
    Aug 2012
    Posts
    6
    Vote Rating
    0
    nannuru is on a distinguished road

      0  

    Default


    Ext.define('app.model.MYModel', {
    extend: 'Ext.data.Model',

    id:'MYModel',


    config: {
    dataIndex: 'details.filed6',
    fields: [
    {
    name: 'filed1',
    type:'string'
    },
    {
    name: 'filed2',
    type:'string'
    },
    {
    name: 'filed3',
    type:'string'
    },
    {
    name: 'filed4',
    type:'string'
    },
    {
    name: 'filed4',
    type:'string'
    },


    {
    name: 'filed6',


    type:'string'
    }
    ]


    }
    });

    Is the above model is fine for the JSOn mentioned above?

  6. #6
    Sencha - Community Support Team sword-it's Avatar
    Join Date
    May 2012
    Location
    Istanbul
    Posts
    1,333
    Answers
    124
    Vote Rating
    85
    sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough

      0  

    Default


    @nannuru,

    your model are not valid, the valid model for above mentioned json are -

    Code:
       
    Ext.define('MainModel', {
      extend:'Ext.data.Model',
    
     fields:[
         {name:'field1'},
          ....................,
         {name:'field5'},
         {name:'field6', mapping:'details.field6'},
         {name:'field7', mapping:'details.field7'}
       ],
      hasMany:{model:'Address', name:'adddetails'}
    })
    
    
    Ext.define('Address', {
    extend:'Ext.data.Model',
    fields:[
      {name:'field8'},
      {name:'field9'}
     ],
      belongsTo:'MainModel'
    })
    sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.

  7. #7
    Sencha User
    Join Date
    Aug 2012
    Posts
    6
    Vote Rating
    0
    nannuru is on a distinguished road

      0  

    Default


    code:-

    Code:
    Ext.define('app.model.MYModel', {
        extend: 'Ext.data.Model',
               
               id:'MYModel',
    
    
        config: {
               dataIndex: 'details.filed6',
            fields: [
                {
                    name: 'filed1',
                     type:'string'
                },
                {
                    name: 'filed2',
                     type:'string'
                },
                {
                    name: 'filed3',
                     type:'string'
                },
                {
                   name: 'filed4',
                     type:'string'
                },
                {
                     name: 'filed4',
                     type:'string'
                },
               
               
                     {
                     name: 'filed6',
                  
                     
                     type:'string',
                    mapping: 'details.filed6'
                     }
     {
                     name: 'filed7',
                  
                     
                     type:'string',
                    mapping: 'details.filed7'
                     }
            ]
               
        
        }
    });

    Store:-


    Code:
    Ext.define('app.store.MYStore', {
               extend: 'Ext.data.Store',
               id:'MYStore',
               config: {
               model: 'app.model.MYModel',
               
               proxy: {
               type: 'ajax',
               url: /tempjson
               reader:  {
               type:'json',
               
               },
               writer: {
               type : 'json',
          
               writeAllFields: true,
               nameProperty : 'mapping',
               successProperty : 'success'
               
               }
               },
               autoLoad: true,
               timeout: 5000,
                         
               
            }});

    View:-

    Code:
    Ext.define('app.view.MYPanel', {
        extend: 'Ext.form.FormPanel',
        xtype: 'MYFormPanel',
               id:'MYFormPanel',
    config: {
    items: [
    
    
                                  {
                                  xtype: 'fieldset',
                                  id:'myfiledset',
                                  title: 'MyJSONfirstlist',
    }
     items: [
    
    
     {
                                          xtype: 'textfield',
                                          label: 'field1:',
                                          name: 'field1',
                                          },]},
    
    
                                  {
                                  xtype: 'fieldset',
                                  id:'myfiledset',
                                  title: 'MyJSONfirstlistdetails',
    }
     items: [
    
    
     {
                                          xtype: 'textfield',
                                          label: 'field6:',
                                          name: 'field6',
                                          },
    
    
     xtype: 'textfield',
                                          label: 'field7:',
                                          name: 'field7',
                                          }]},
    Controller:=


    Code:
    this.getMyform().setRecord(Ext.getStore("MYStore").getAt(0));
    filed6 and filed 7 are not getting loaded.

Thread Participants: 3

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi