Currently, I am working on incorporating nested comments using both Backbone and Rails. In my current setup on the server side, comment models are utilized to store the unique identifier parent_comment_id
(assuming they have one). Whenever the application requests comments for a specific entity, I send back a JSON object whereby the keys represent the parent_comment_id
s while the corresponding values consist of arrays of comments linked to that given parent comment ID. For example:
{
"" : [{id: 1, content: "I'm an unnested comment, parent_comment_id: ""}],
1 : [{id: 2, content: "I am nested under the comment with an id of 1", parent_comment_id: 1}, etc.],
...
}
The primary issue at hand currently is that the Comments collection in Backbone is returning an array of length 1, where the only element found within is the comments hash.
Is there a way for me to customize or override the parsing of the JSON response conducted by the Comments collection in order to ensure that the response returned is the JSON response hash instead of an array?