2014-11-04 154 views
1

我有一个帖子一个简单的模板与评论:Ractive结合于母公司

{{#each Posts}} 
    {{Text}} 
    {{#each Comments}} 
    //how can I bind to Post.Id here? Like {{../Id}} 
    {{/each}} 
{{/each}} 

我如何可以绑定到父#each块(我需要交的id属性)的注释中#each块?

回答

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}} 
+0

试过{ {../Id}}语法,但它似乎并没有工作:http://jsfiddle.net/pj6myzch/3/ – SiberianGuy 2014-11-04 15:42:59

+0

虽然#with的方法工程 – SiberianGuy 2014-11-04 16:10:10

+0

对不起,需要去两个路径,一个'评论','到'Posts'。见http://jsfiddle.net/pj6myzch/4/。修正例子。 – martypdx 2014-11-05 13:11:30