0

I have such jade snippt:

div.comment_list
    - var clist = comment_list
    each comment in clist
        div.comment
            div.comment_detail
                span.commentator comment.commentator
                span.comment_time comment.comment_time
                span.comment_content comment.comment_content

The comment_list is what I pass into the jade template.

The problem is : Each array element comment consists of a compound object, which, as you saw, has commentator, comment_time, and comment_content.

However, jade could not recognize this fact, and it just output : comment.commentator comment.comment_time, comment.comment_content vebatim.

So how to tackle this ?

4

2 回答 2

4

你也不需要- var一切。例如。

div.comment_list
    each comment in comment_list
        div.comment_detail
            span.commentator #{comment.commentator}
            span.comment_time #{comment.comment_time}
            span.comment_content #{comment.comment_content}

如果您要输出单个变量,则不需要#{}包装器。仅当您在其中混合纯文本时才需要它。

div.comment_list
    each comment in comment_list
        div.comment_detail
            span.commentator= comment.commentator
            span.comment_time= comment.comment_time
            span.comment_content= comment.comment_content

并且 div 是多余的 - 您可以简单地使用我们.class#id两者。显然,如果您没有设置类或 id,则需要在div此处设置单词。

.comment_list
    each comment in comment_list
        .comment_detail
            span.commentator= comment.commentator
            span.comment_time= comment.comment_time
            span.comment_content= comment.comment_content
于 2013-05-10T03:41:38.813 回答
-1

我已经想通了。

让代码说话:

div.comment_list
    - var clist = comment_list
    each comment in clist
        - var commentator = comment.commentator
        - var comment_time = comment.comment_time
        - var comment_content = comment.comment_content
        div.comment_detail
            span.commentator #{commentator}
            span.comment_time #{comment_time}
            span.comment_content #{comment_content}
于 2013-05-09T04:51:29.417 回答