Closed romanown closed 4 years ago
JsRender tags only allow 'valid JsRender paths and expressions' (see https://www.jsviews.com/#paths) and that does not include global functions such as RegExp()
nor does it include RegExp expressions /.../
.
You can either preprocess your data values before passing them to JsRender, or if you want you can use a helper function or converter, so your RegExp code is not directly in the template markup. You can even pass in the regular expression as a parameter to the helper function or converter, as in this example:
$.views.converters("regexReplace", function(value, regex, repl) {
return value.replace(new RegExp(regex, 'g'), repl)
});
with
{{regexReplace:key "[^a-zA-Z0-9]" "_"}}
thank You for fast answere
{{:key.replace(/[^a-zA-Z0-9]/, "_")}}
if argument 38.5 result 8.5. if `{{:key.replace(/[^a-zA-Z0-9]/g, "")}}error
Object { name: "JsRender Error", message: "Syntax error\nCompiled template code:\n\n// jsvTmpl/if/for\nvar v,t=j._tag,ret=\"\"+\"\n\t\t\t\t\t\t<div class=\\"js-block\"\n+((v=data.key.replace(/[j.sq(.a-data.zA-data.Z0-9)]/data.g,\"\"))!=null?v:\"\")`