Results 1 to 3 of 3

Thread: add data to nested store.

  1. #1
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    48
    Vote Rating
    0
      0  

    Default add data to nested store.

    hello^^

    i make model like this.
    HTML Code:
     Ext.define('refDMC', {
            extend: 'Ext.data.Model', 
           fields: [ 
                       { name: 'DM', type: 'string' },
                       { name: 'idx', type: 'string' }, 
                   ],
           hasMany:[  
                           { 
                                model:'subRefDMC', 
                                name:'sub',
                                 associationKey:'DM'                         }                         ]    });
     
       Ext.define('subRefDMC', { 
           extend: 'Ext.data.Model', 
           fields: [
                        { name: 'DM', mapping:'record[0].DM' }, 
                       { name: 'idx', mapping:'record[1].idx' }, 
                   ],
            association:[ 
                         {type:'belongTo',model:'refDM'} 
                         ] 
               });

    and my store is

    HTML Code:
    var refDMC = Ext.create('Ext.data.Store',{ 
           model:'refDMC',
            proxy:{
                type:'memory' 
           },
            autoLoad:false,
            handler:{ 
               load:function(store,rec){
                    console.log(store); 
               }
            }
        })
    when i get data from server

    the data is

    HTML Code:
    {"items":[
    {
    "DM":"DMC-JHS182-AAAA-HD4-10-0001-00000-018A-A_001_EN",
    "idx":21,
    "DMS":[
         {"DM":"DMC-JHS182-AAAA-HG7-00-0001-00000-053B-A_001_EN","idx":31}
         ]
    },
    {
    "DM":"DMC-JHS182-AAAA-HG7-00-0001-00000-053B-A_001_EN",
    "idx":31,
    "DMS":[
    {"DM":"DMC-JHS182-AAAA-HG7-00-0000-00000-413A-A_001_EN","idx":41},
    {"DM":"DMC-JHS182-AAAA-HG7-00-0001-00000-420A-A_001_EN","idx":42},
    {"DM":"DMC-JHS182-AAAA-HG7-00-0001-00000-420A-A_001_EN","idx":42},
    {"DM":"DMC-JHS182-AAAA-HG7-00-0001-00000-420A-A_001_EN","idx":42}
    ]
    }],
    "success":false
    }
    how to i can insert data to my store?

    please help.

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,381
    Answers
    3997
    Vote Rating
    1536
      0  

    Default

    2 big issues.

    Your JSON has success = false and the mapping in the subRefDMS was bad:

    Code:
    Ext.define('refDMC', {
        extend  : 'Ext.data.Model',
        fields  : [
            'DM',
            'idx'
        ],
        associations : [
            {
                type           : 'hasMany',
                model          : 'subRefDMC',
                name           : 'sub',
                associationKey : 'DMS'
            }
        ]
    });
    
    Ext.define('subRefDMC', {
        extend      : 'Ext.data.Model',
        fields      : [
            'DM',
            'idx'
        ],
        association : [
            {
                type : 'belongTo',
                model : 'refDM'
            }
        ]
    });
    Used this store locally:

    Code:
    new Ext.data.Store({
        autoLoad  : true,
        model     : 'refDMC',
        proxy     : {
            type   : 'ajax',
            url    : 'data/json.json',
            reader : {
                type : 'json',
                root : 'items'
            }
        },
        listeners : {
            load : function (store, recs) {
                var rec = recs[0],
                    sub = rec.sub();
    
                console.log(sub);
            }
        }
    });
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  3. #3
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    48
    Vote Rating
    0
      0  

    Default thanx^^

    i modified my code.

    but still i don't know about add data to my store
    HTML Code:
    Ext.ajax{(
             type:'GET',
             url:'user.json',
             success:function(response){
                       //I don't know about here.
                       var json = Ext.decode(response.responseText);
                      var store = Ext.get('storeId');
                     store.add(json);//<-------how do i insert data to my nested store
          },
          failure:function(response){
    
    }
    
    )}
    do you have any idea?

Posting Permissions

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