0

there are some data:

var data = [
  {id:"a",b:[{name:"1",value:"a"},{name:"2",value:"x"}],c:"a"}
  {id:"b",b:[{name:"2",value:"b"},{name:"3",value:"c"}],c:"b"}
]

and in the Template

...
{{#each data}}
 {{id}}
   select>
  {{#each b}}
       option   {{#if equal value c}} selected   {{/if}}   >
           name
       option>
  {{/each}}
  
{{/each}}
..

The function:

 Template.temp.equal = function(value,test){
     console.log(value);
     console.log(test);
  }

and the "test" is undefined,In other words,In the second #each can't read the value of the First #each . What's the step I have forgotten? how can I get the value of property "c" in second #each ?

go-oleg
  • 19,272
  • 3
  • 43
  • 44
L.T
  • 2,539
  • 3
  • 20
  • 30

1 Answers1

0

U can do it with registerHelper;

Handlebars.registerHelper("equal",function(value,test,options) {
    if(value==c)
       return options.fn(this);
    return options.inverse(this);
});

And your template

{{#equal value c}}
   selected
{{/equal}}
delibalta
  • 300
  • 2
  • 11