Monthly Archives: Juni 2019
Handlebars render Funktion wie bei Mustache
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
Handlebars.registerHelper('select', function (value, options) { // Create a select element var select = document.createElement('select'); // Populate it with the option HTML select.innerHTML = options.fn(this); // Set the value select.value = value; // Find the selected node, if it exists, add the selected attribute to it if (select.children[select.selectedIndex]) select.children[select.selectedIndex].setAttribute('selected', 'selected'); return select.innerHTML; }); Handlebars.render = Handlebars.render || function(tpl, data) { data = data || {}; var compiled = Handlebars.render.cache[tpl]; if (!compiled) { // Uncached template compiled = Handlebars.compile(tpl); Handlebars.render.cache[tpl] = compiled; } return compiled(data); }; Handlebars.render.cache = {}; |
0
Login