Login Register

Using modified JSON Store w/ Grid

Hello,

I am currently in the process of trying to implement a grid using a JSON store. I have successfully done this with a JSON file that followed the ItemFileReadStore.js requirements of using an items array. I have recently been trying to figure out how best to use a custom JSON store hierarchy with my grid. The store looks like the following:

{ 
      	"top": [ 
               {"id":1, "name": "Name1", "width":2, 
                    "first":[	
                            {"card":1, "circuit":7},
                            {"card":1, "circuit":8} 
                        ], 
                    "second":	[	
                            {"card":2, "circuit":1, "in":1, "func":0}
                        ] 
                },
                {"id":2, "name": "Name2", "width":1, 
                    "first":[	
                            {"card":1, "circuit":4}
                        ], 
                    "second":	[	
                            {"card":2, "circuit":2, "in":1, "func":1},
                            {"card":2, "circuit":3, "in":1, "func":2},
                            {"card":2, "circuit":4, "in":1, "func":3},
                            {"card":2, "circuit":5, "in":1, "func":4},
                            {"card":2, "circuit":6, "in":1, "func":5},
                            {"card":2, "circuit":7, "in":1, "func":6}
                        ] 
                }

            ] 
}

I have found the following post which looks like it may be what I want to do but I am too new to JS to really have any clue what needs to go in the rawdata section at the bottom.

http://www.dojotoolkit.org/forum/dojo-core-dojo-0-9/dojo-core-support/ma...

Right now I can simply change the ItemFileReadStore.js file to use src instead of items ~line 450 this._arrayOfTopLevelItems = dataObject.top; And by doing do I can access the id, name and width fields but none of the first or second arrays or items within these arrays. I have used firebug to debug the code and can see that it is reading all fields of the JSON storage file however I am not sure how to access them or if more modifications are needed.

I was hoping I could just modify my layout view for the grid using dot notation but that doesn't work to access the secondary arrays.

var simple_top_view = {
				cells: [
					[{field: "id", name: 'ID', width: "3em"},
					{field: "name", name: 'Name', width: "7em"},
					{field: "width", name: 'Width', width: "5em"},
					{field: "first[0].card", name: 'Card#', width: "4em"},
					{field: "second[0].circuit", name: 'Circuit#', width: "5em"}]
					]};

If I use just card or just circuit it doesn't work either (not even incorrect data just ?'s).

So the question does anyone have some helpful hints on how to tackle this problem, I have very limited JS experience which is probably making this much harder to accomplish. This is essentially what I would like to see in the end on the grid:

ID | NAME | WIDTH | FIRST | CARD | CIRCUIT | SECOND | CARD | CIRCUIT | IN | FUNC |
----------------------------------------------------------------------------------
1  | Nam1 |  2    |   1   |   1  |    7    |    1   |   2  |    1    |  0 |   0  |
   |      |       |   2   |   1  |    8    |        |      |         |    |      |
----------------------------------------------------------------------------------
2  | Nam2 |  1    |   1   |   1  |    4    |    1   |   2  |    2    |  1 |  1   |
   |      |       |       |      |         |    2   |   2  |    3    |  1 |  2   |
   |      |       |       |      |         |    3   |   2  |    4    |  1 |  3   |
   |      |       |       |      |         |    4   |   2  |    5    |  1 |  4   |
   |      |       |       |      |         |    5   |   2  |    6    |  1 |  5   |

Hopefully the above table is readable :-)

Thank you all for your help and time, it is much appreciated.
-Alex