2017-05-17 2 views
1

Ich möchte Iterationswerte mit Lenker vergleichen. Das ist mein CodeVergleichen Iterationswerte mit Lenker

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

Bitte helfen. Ich bin neu im Lenker/

Antwort

0

Verwenden Sie die {{compare}} Helfer aus dem handlebars-helpers Modul.

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

Siehe die documentation, wie die Helfer installieren und zu nutzen.

0

Sie können dies mit einem einfachen helpers in Handlebars wie so:

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

und im Code ...

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