0
votes

I am new to Sencha touch and need your help to resolve the issue. I am trying to display the list of children text using following JSON and Sencha touch code. I looked thorough the API and found that the Child data can be accessed, but then I am not sure how I can send that back to Panel/Store to display the list as

  • Child 21
  • Child 22

I have nested JSON data as follows:

    {
   "items":[
       {
         "id":"1",
         "text": "Parent 1",
         "leaf": false,
         "items": [
              {
                  "id":1,
                  "text": "child 1",
                  "leaf": true
              },
              {
                   "id":2,
                   "text": "child 2",
                   "leaf": true
              }
         ]
    },
    {
        "id":"2",
        "text": "Parent 2",
        "leaf": false,
        "items": [
            {
                "id":3,
                "text": "child 21",
                "leaf": true
            },
       {
                "id":4,
                "text": "Child 22",
                "leaf": true
            }
         ]
      }
    ]
  }

Now my sencha touch code is as follows:

  Ext.ns('MyApp');
  MyApp.Child= Ext.regModel(Child, {
    fields: ['id','text','day','date'],
    belongsTo: 'Parent',
    idProperty:'id',
    proxy: {
         type: 'rest',
         url: 'test.json'
    }
  });
  MyApp.Parent = Ext.regModel('Parent', {
    fields: [
      {name: 'id', type: 'int'},
      {name: 'text', type: 'string'}
     ] ,
      associations: [
            { type: 'hasMany', model: 'Child', name: 'items'}
      ],
      proxy: {
        type: 'ajax',
        url: 'test.json'
   }

  });
  MyApp.parentStore = new Ext.data.Store({
     model : 'Parent',
     proxy: {
        type: 'rest',
        url: 'test.json',
        reader: {
            type: 'json',
            root : 'items'
         }
      },

      autoLoad:true 
   });

   MyApp.parentStore.filter('id','2');

// Do something here to get the list of child items.

//   MyApp.childStore = ?   

   MyApp.appList = new Ext.Panel ({
        fullscreen  : true,
        dockedItems : [
             {
                  xtype : 'toolbar',
                  title : 'Applications',
                  dock : 'top'
             }
        ],
        items: [{
        xtype: 'list',
        store: MyApp.childStore, // ??????
        itemTpl: '<div class="contact"><strong>{text}</strong></div>'
    }]                     

 });
1

1 Answers

2
votes