I have the following function that processes an AJAX callback in jQuery:
function success(data) { var templateData = { items: data, formatMoney: function () { return function (value) { return Globalization.format(value, 'N'); }; } };
Here's what my template looks like:
{#Items}} <tr> <td>{{ProductId}}</td> <td>{{#formatMoney}}{{Cost}}{{/formatMoney}}</td> </tr> {{/Items}}
The problem is that instead of the value of Cost I get {{Cost}}. I know that this should work as described in the mustache manual (http://mustache.github.com/mustache.5.html), but I would like to get the value instead.
this will point to my product object, so I could get the value using this.Cost , but this is for a simple case, and I have many types of objects with many properties that require formatting, so I need a general solution for storing DRY things .
I could also calculate this on the server side, but I prefer to do it on the client side, since I not only use this data with hogan, but also for other client-side calculations.
Is there a more direct, general, and client-side way to get the value of Cost instead of an unloaded literal?
source share