javascript - Each is not working as supposed with Handlebar -


in app use handlebar 4.0.3, have simple template :

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

and use compile :

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

i have result :

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

i think should have "test" instead of "[object object]".

i tried template :

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

and javascript :

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

and 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 can see, {{name}} gives nothing instead of "name".

am doing wrong?

edit 1

i found problem.

i have html :

  <div id='modal-site'>     <table>       <tbody>         {{#each site.certificates}}         <tr>           <td>{{this.name}}</td>         </tr>         {{/each}}       </tbody>     </table>   </div> </div> 

when $('#modal-site').html(), have result :

{{#each site.certificates}}  {{/each}} <table>   <tbody><tr>     <td>{{this.name}}</td>   </tr></tbody> </table> 

with each outside handlebars cannot work. have idea of solution ?

for second implementation of template, should use {{this.name}} in html if want access string data.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -