Answer the question
In order to leave comments, you need to log in
How to use custom helper in each?
How to use the custom helper is clear. But how to use and register it if I have an array and I iterate through it through each?
Small example (working jsfiddle.net )
var dataTest = {
total: 4,
invoices: [
{
id: 1,
var1: 354,
var2: 'Test1',
}, {
id: 2,
var1: 300,
var2: 'Test2',
}, {
id: 3,
var1: 124,
var2: 'Test3',
}, {
id: 4,
var1: 354,
var2: 'Test4',
},
]
};
var template = Handlebars.compile($('#templateInvoice').html());
$('#invoiceList').html(template(dataTest));
data.invoices.forEach(function(item, i, arr) {
Handlebars.registerHelper('var1check', function(item.var1) {
if (item.var1 == 354) {
return 'Значение 1';
} else {
return 'Значение 2';
}
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question