我有一个包含评论的帖子的简单模板:
{{#each Posts}}
{{Text}}
{{#each Comments}}
//how can I bind to Post.Id here? Like {{../Id}}
{{/each}}
{{/each}}
如何在#each块注释中绑定父级#each块(我需要获取帖子的Id属性)?
答案 0 :(得分:4)
Ractive支持Restricted References,就像你拥有它一样:
{{#each Posts}}
{{Text}}
{{#each Comments}}
Post Id: {{../../Id}}
Comment Id: {{Id}}
{{/each}}
{{/each}}
如果您不需要对别名字段进行双向更新,也可以将父字段设为别名:
{{#each Posts}}
{{Text}}
{{#with { PostId: Id } }}
{{#each Comments}}
Post Id: {{PostId}}
Comment Id: {{Id}}
{{/each}}
{{/with}}
{{/each}}