javascript - Ractive 绑定(bind)到父级

标签 javascript ractivejs

我有一个带有评论的帖子的简单模板:

{{#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/

相关文章:

javascript - 如何在 Google Chrome 扩展中使用 jQuery ajax?

ractivejs - 如何在 active 组件之间共享行为

javascript - 读取 Ractive.js 中的计算属性

javascript - RactiveJS 和时间条件 DOM

javascript - 声明式与编程式 GraphQL

javascript - 如何轻弹 DIV 并让它朝正确的方向移动?

javascript - 如何访问未压缩到 nw.js 中的 nw 包中的本地资源

javascript - 如何使用 HTML、CSS 和 JQuery 使菜单从移动设备的右侧滑动?

javascript - 是否可以在 RactiveJS 中使用计算函数?