我有一个带有评论的帖子的简单模板:
{{#each Posts}}
{{Text}}
{{#each Comments}}
//how can I bind to Post.Id here? Like {{../Id}}
{{/each}}
{{/each}}
如何在评论#each block 中绑定(bind)父#each block (我需要获取帖子的 Id 属性)?
最佳答案
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}}
关于javascript - Ractive 绑定(bind)到父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26730891/