mercredi 30 septembre 2015

Each is not working as supposed with Handlebar

In an app that use Handlebar 4.0.3, I have this simple template :

{{#each certificates}}
  <tr>
    <td data-title='Certification'>{{this}}</td>
  </tr>
{{/each}}

And I use compile it like this :

result = template(certificates: ['test'])

I have this result :

<table class="table table-hover table-condensed tablesorter">
  <tbody><tr>
    <td data-title="Certification">[object Object]</td>
  </tr></tbody>
</table>

I think I should have "test" instead of "[object Object]".

I tried with this template :

{{#each certificates}}
<tr>
  <td data-title='Certification'>{{this}}</td>
  <td data-title='Certification'>{{name}}</td>
</tr>
{{/each}}

And this JavaScript :

result = template({ certificates: [{name: 'Name'}]})

And I have tyhis result :

<table class="table table-hover table-condensed tablesorter">
  <tbody><tr>
    <td data-title="Certification">[object Object]</td>
    <td data-title="Certification"></td>
  </tr></tbody>
</table>

As you can see, {{name}} gives nothing instead of "Name".

Am I doing something wrong?




Aucun commentaire:

Enregistrer un commentaire