对父母具有种族约束力
Ractive binding to parent
我有一个简单的带有评论的帖子模板:
{{#each Posts}}
{{Text}}
{{#each Comments}}
//how can I bind to Post.Id here? Like {{../Id}}
{{/each}}
{{/each}}
我如何绑定到每个区块评论内的父区块(我需要获取帖子的Id属性)?
Racive支持受限引用,所以就像您拥有的一样:
{{#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}}