【问题标题】:Creating UI comment component with blaze使用 blaze 创建 UI 注释组件
【发布时间】:2016-09-17 20:13:11
【问题描述】:

我正在尝试使用 Blaze 创建一个 cmets 组件,但我不知道如何处理回复。

这是“评论”元素的架构:

_id、authorId、message、replies(这些是评论 ID)、isReply(布尔值)。

然后我用html创建了一个模板

{{#each message}}
 <div class="message">
   <h2>{{author}}</h2>
   <p>{{message</p>
   <a class="button">Reply</a>
 </div>
     {{#each replies}}
       <div class="message">
         <h2>{{author}}</h2>
         <p>{{message</p>
         <a class="button">Reply</a>
       </div>
     {{/each}}
{{/each}}

那么,我如何处理回复的回复?有什么想法吗?

【问题讨论】:

    标签: meteor meteor-blaze


    【解决方案1】:

    您需要递归地使用模板An example

    在您的情况下,类似于以下内容:

    {{#each message}}
     <div class="message">
       <h2>{{author}}</h2>
       <p>{{message</p>
       <a class="button">Reply</a>
     </div>
         {{#each replies}}
           {{> reply}}
         {{/each}}
    {{/each}}
    
    <template name="reply">
      <div class="message">
      <h2>{{author}}</h2>
      <p>{{message</p>
      <a class="button">Reply</a>
      {{#each replies}}
        {{> reply}}
      {{/each}}
    </div>
    </template>
    

    您需要一个 replies 帮助器,用于获取对该回复的回复的 reply 模板。

    【讨论】:

    • 谢谢你,米歇尔。我现在如何匹配两个助手?我的意思是让回复显示正确的回复消息数组。
    • 这取决于您如何对回复的回复进行建模。有家长回复键吗?
    猜你喜欢
    • 1970-01-01
    • 2010-10-23
    • 2018-05-18
    • 2016-02-27
    • 2012-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-08
    相关资源
    最近更新 更多