簡體   English   中英

使用把手比較迭代值

[英]Compare iteration values using handlebars

我想使用把手比較迭代值。 這是我的代碼

{{#each accounts}}
   {{#each projects}}
      {{#if}} (compare accounts.project_id with projects._id)
          // display the project name
      {{else}}
          // display not found
      {{/if}}
   {{/each}}
{{/each}}

請幫忙。 我是車把的新手/

使用handlebars-helpers模塊中的{{compare}}幫助器。

{{#each accounts}}
   {{#each projects}}
      {{#compare accounts.project_id "==" projects._id)
          // display the project name
      {{else}}
          // display not found
      {{/compare}}
   {{/each}}
{{/each}}

請參閱有關如何安裝和使用幫助程序的文檔

您可以在Handlebars使用簡單的幫助程序 ,如下所示:

Handlebars.registerHelper('if_eq', function(a, b, opts) {
    if(a == b)
        return opts.fn(this);
    else
        return opts.inverse(this);
});

在你的代碼中......

 {{#each accounts}}
     {{#each projects}}
       {{#if_eq accounts.project_id projects._id}}
          // display the project name
      {{else}}
          // display not found
      {{/if_eq}}
   {{/each}}
{{/each}}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM