Added more helpers + Improved app.template to support custom assignments
This commit is contained in:
parent
7ff5c076fa
commit
9e06563344
|
@ -22,7 +22,7 @@ app.template = {
|
|||
return cback(html);
|
||||
});
|
||||
},
|
||||
fill: function(data, tpl) {
|
||||
fill: function(data, tpl, customCback) {
|
||||
const res = Array.from(tpl.matchAll(/\{\.[^\{\}]+\}/g));
|
||||
var matches = [];
|
||||
for (var i = 0; i < res.length; i++) {
|
||||
|
@ -33,7 +33,12 @@ app.template = {
|
|||
for (var i = 0; i < matches.length; i++) {
|
||||
const k = matches[i];
|
||||
if (k.match(/^[a-zA-Z0-9_\.]+$/)) {
|
||||
const v = eval(`data.${k}`);
|
||||
var v = eval(`data.${k}`);
|
||||
if (customCback !== undefined) {
|
||||
var newv = customCback(k, v);
|
||||
if (newv !== undefined)
|
||||
v = newv;
|
||||
}
|
||||
if (v !== undefined)
|
||||
tpl = tpl.replaceAll('{.'+k+'}',v);
|
||||
}
|
||||
|
|
|
@ -37,9 +37,8 @@ function loadScript(id, file, cback) {
|
|||
document.body.appendChild(script);
|
||||
}
|
||||
|
||||
function getNormalizedURI() {
|
||||
return window.location.pathname.replace(/\/+?$/, '');
|
||||
}
|
||||
function getNormalizedURI() { return window.location.pathname.replace(/\/+?$/, '') }
|
||||
function capitalize(s) { return s.charAt(0).toUpperCase() + s.substr(1) }
|
||||
|
||||
function JSON_to_URLEncoded(element,key,list) {
|
||||
var list = list || [];
|
||||
|
|
Loading…
Reference in New Issue