javascript - Pass object as parameter to onclick method in handlebars template -
i have json looks this:
{ list: [ { name: 'aaa', id: 1, age: 34 }, { name: 'bbb', id: 2, age: 24 } ] }
and template this:
<ul> {{#each list}} <li onclick="somefunc({{this}})">{{name}} ({{age}}) </li> {{/each}} </ul>
basically want pass current object , function it.
now if seek it, generated html has
... onclick="somefunc( [object object] )" ...
whereas i'd similar this:
... onclick="somefunc( {name: 'aaa', id: 1, age: 34} )" ...
how can prepare this?
posting future references:
got reply here:
handlebars.js parse object instead of [object object]
turns out handlebar tostring on info before pasting template. had register helper method converts json.
handlebars.registerhelper('json', function(context) { homecoming json.stringify(context); }); <li onclick="somefunc({{json this}})">{{name}} ({{age}}) </li>
javascript json handlebars.js
No comments:
Post a Comment