Closed joviqiao closed 8 years ago
You need a helper. Check here: https://github.com/assemble/handlebars-helpers
If it doesn't fit your needs then you can write your own. It is pretty simple.
@hguillermo Thx, it work, but {{sum [user.tj1num,user.tj2num,user.tj3num] }} {{sum "[{{user.tj1num}},{{user.tj2num}},{{user.tj3num}}]" }} How to create array can get sum ?
You are trying to use a helper inside a helper. The syntax is different. Check this: http://stackoverflow.com/questions/14781916/is-it-possible-to-nest-helpers-inside-the-options-hash-with-handlebars
If not you can create your own helper and pass the array and return the sum or whatever you need.
Thx
{{ user }}
<tr>
<td>{{user.Phone}}</td>
<td>{{user.name}}</td>
<td>
<select class="trendSet">
<option {{if user.trend eq 0}}selected="selected"{{/if}} value="0">No trend</option>
<option {{if user.trend eq 1}}selected="selected"{{/if}} value="1">trend</option>
<option {{if user.trend eq 2}}selected="selected"{{/if}} value="2">wait</option>
<option {{if user.trend eq 3}}selected="selected"{{/if}} value="3">want</option>
</select>
</td>
</tr>
Hi @hguillermo above, my problem is: user.trend ( backend data ) judge eq number, like ==, + - * / , there have backend data. Thx
@hguillermo How to write my own sum array helper function and use it in {{sum array}} handlebars without install handlebars-helpers? Can you help?
@shone83 I would like to help you but it is been many years without handlebars. I barely remember it. I am fully working on React the last 3 years. I am sure there are still some tutorials on the internet.
Ok, you said it's pretty simple so I thought that could do it.
data sometime need add , subtract , multiply and divide, How to do it? if i create helper, numerous functions...: data: [{name:user1,buytimes:2},{name:user2,buytimes:4},...] now, i need get all of buytimes, How to do it in page?