Parsing parse.com+;主干检索用户的嵌套对象集

Parsing parse.com+;主干检索用户的嵌套对象集,parsing,backbone.js,nested-datalist,Parsing,Backbone.js,Nested Datalist,我想扩展parse.com在其教程中提供的内容,以处理主干集合和第二级数据(注释)。目前,exmaple正在检索用户的帖子列表,数据结构如下: USER -------------------------------------- | User_ID | Username | ...... -------------------------------------- | 1 | John | ........ | 2 | Jane | .......

我想扩展parse.com在其教程中提供的内容,以处理主干集合和第二级数据(注释)。目前,exmaple正在检索用户的帖子列表,数据结构如下:

USER
--------------------------------------
| User_ID |  Username | ......
--------------------------------------
| 1       |  John     | ........
| 2       |  Jane     | ........


POST 
--------------------------------------
| POST_ID  |  User_ID | Title    | .....
--------------------------------------
| 20       |  1       | abcdefg  | .....
| 21       |  1       | svsvdsv  | .....
COMMENT
-----------------------------------------------------------------------
| COMMENT_ID  |  POST_ID  |  Comment_Text        | Title    | .....
-----------------------------------------------------------------------
| 30          |  21       |  awesome post woohoo | abcdefg  | .....
| 31          |  21       |  terrible post....   | svsvdsv  | .....
我想扩展这个调用,以便在每个帖子中返回相应的评论。这意味着将有一个api调用来解析,该调用将为登录用户返回所有帖子和这些帖子的所有注释(正确嵌套)。下面是注释数据结构的示例:

USER
--------------------------------------
| User_ID |  Username | ......
--------------------------------------
| 1       |  John     | ........
| 2       |  Jane     | ........


POST 
--------------------------------------
| POST_ID  |  User_ID | Title    | .....
--------------------------------------
| 20       |  1       | abcdefg  | .....
| 21       |  1       | svsvdsv  | .....
COMMENT
-----------------------------------------------------------------------
| COMMENT_ID  |  POST_ID  |  Comment_Text        | Title    | .....
-----------------------------------------------------------------------
| 30          |  21       |  awesome post woohoo | abcdefg  | .....
| 31          |  21       |  terrible post....   | svsvdsv  | .....

任何帮助都将不胜感激

Backbone.js不支持嵌套模型,因此您可以将Backbone-relational.js用于嵌套模型

Backbone-relational.js为主干网提供了模型之间的一对一、一对多和多对一关系

班级

User = Backbone.Relational.Model({
    defaults : {
        id : '',
        name : '',
        posts : [], //collection
    },
    relation : [{
        type : 'HasMany',
        key : 'posts',
        relatedModel : 'com.dw.attendance.model.Post',
        reverseRelation : {
            key : 'user'
        }
    }]
});

Post = Backbone.Relational.Model({
    defaults : {
        id : '',
        user : '', //model
        comments : '', //collection
        title : '',
    },
    relation : [{
        type : 'HasOne',
        key : 'user',
        relatedModel : 'com.dw.attendance.model.User',
        reverseRelation : {
            key : 'posts'
        }
    },{
        type : 'HasMany',
        key : 'comments',
        relatedModel : 'com.dw.attendance.model.Comment',
        reverseRelation : {
            key : 'post'
        }
    }]
});


Comment = Backbone.Relational.Model({
    defaults : {
        id : '',
        post : '',//model
        text : '',
        title : ''
    },
    relation : [{
        type : 'HasOne',
        key : 'post',
        relatedModel : 'com.dw.attendance.model.Post',
        reverseRelation : {
            key : 'comments'
        }
    }]
});
您的数据如下,对于用户:
{id:1,name:'john',posts:[1,2,3]}

然后你可以通过

user.get('posts').get('post_ID').get('comments');