0
votes

I am having a nested json as follows. I want to parse this to TreePanel,

 {"E": {
              "@st": "SS",
              "eid": "879",
              "name": "L-e",
              "code1": "01",
              "E":   [
                    {
                  "@st": "SS",
                  "eid": "423",
                  "name": "PaM-M",
                  "code1": "S-M",
                },
                    {
                  "@st": "SS",
                  "eid": "890",
                  "name": "P-F",
                 "code1": "S-F",
                  "E":       [
                            {
                      "@st": "SS",
                      "eid": "342",
                      "name": "S-p",
                     "code1": "S-L"
                    },
                            {
                      "@st": "SS",
                      "eid": "967",
                      "name": "St-k",
                      "code1": "ST-K"
                    },
                            {
                      "@st": "SS",
                      "eid": "789",
                      "name": "S-k",
                      "code1": "S-A"
                    }
                  ]
                },
                    {
                  "@st": "SS",
                  "eid": "908",
                  "name": "S-F",
                  "code1": "S-EF",
                  "E":       [
                            {
                      "@st": "SS",
                      "eid": "567",
                      "name": "S-M",
                      "code1": "ST-TK",
                    },
                            {
                      "@st": "SS",
                      "eid": "456",
                      "name": "S-Teak",
                      "code1": "S-TK"
                    },
                            {
                      "@st": "SS",
                      "eid": "234",
                      "name": "S-PK",
                      "code1": "S-ML"
                    }
                  ]
                },
                    {
                  "@st": "SS",
                  "eid": "2345",
                  "name": "A-Pedestal-Common",
                  "code1": "AC1"
                },
                    {
                  "@st": "SS",
                  "eid": "1234",
                  "name": "A_P_Wenge",
                  "code1": "A_1"
                }
              ]
            }}

i want to parse this json in TreePanel in Extjs4.i cannot change this json format.
please let me know how i will achive this?
Thanks in Advance.

2
Can you provide some example code that you have tried? I have to agree with Alex's answer to your question in the literal sense, but I don't think that is what you really wanted. - Reimius

2 Answers

2
votes

If I understand you correctly, you're after the code below.

E in your json essentially stands for the children the tree reader expects by default.

 Ext.define('TreeModel', {
    extend: 'Ext.data.Model',
    fields: [ '@st', 'eid', 'name', 'code1' ]
 });

 var iTreeStore = Ext.create('Ext.data.TreeStore', {
     model: 'TreeModel',

     // Your other configs in here.
     proxy: {
        // whatever your proxy comes in here.
     },
     reader: {
        type  : 'json',
        root  : 'E'      // That's the one that should do the trick.
     }
 }); 
0
votes

Just parsing it?

Ext.JSON.decode(jsonString) turns it into an object for you...