PDA

View Full Version : Issue regrading to JSon Nested Structure



Weicheng.Huang
11 Nov 2013, 7:47 AM
Hi,

I set root: "ChatInfo" and model : Body, Name, Data, CommentBody, CommentName, CommentDate. Right now, I am able to read some of the data include: Body, Name, Data, CommentBody, CommentName, CommentDate. However, I am not able the read the replay section which over one reply. For example, I am able to read :"only one reply","Adam","2013-09-18", but not able to read: "Replycomment1" and "Replycomment2" . I set mapping for CommentBody: "CommentsInfo.CommentBody", and try a lot of combinations.

Any advice is welcome. Thanks in advance.



{
"ChatInfo": [
{
"Body": "Hi test",
"Name": "LBJ",
"Date": "2013-09-13"
},
{
"Body": "Hi test2",
"Name": "MJ",
"Date": "2013-09-14"
},
{
"Body": "Hi test3",
"CommentsInfo": [
{
"CommentBody": "Replycomment1",
"CommentName": "Adam",
"CommentDate": "2013-09-15"
},
{
"CommentBody": "Replycomment2",
"CommentName": "Scott",
"CommentDate": "2013-09-15"
}
],
"Name": "Jerry",
"Date": "2013-09-15"
},
{
"Body": "This is test",
"Name": "Jack",
"Date": "2013-09-16"
},
{
"Body": "Hello world",
"CommentsInfo": [
{
"CommentBody": "only one reply",
"CommentName": "Adam",
"CommentDate": "2013-09-18"
}
],
"Name": "Jerry",
"Date": "2013-09-17"
}
],
"ResponseCode": "",
"ReponseMessage": ""
}

burnnat
11 Nov 2013, 10:21 AM
You'll need to use multiple model classes for this: one for your ChatInfo and another for the CommentInfo, linked together with a HasMany (http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.association.HasMany) association. There's a good example of this in the data package guide (http://docs.sencha.com/extjs/4.2.2/#!/guide/data) in the documentation - read the "Associations" section and then the section titled "Loading Nested Data".