我的模板中出现了: {{parseInt(hasshakenum)}} 结果报错: Template Error resultPageTMP Render Error parseInt is not a function 22 parseInt(hasshakenum); 模板内部不支持原生js方法?请问怎么写才能支持?
artTemplate内部没有处理parseInt这个函数,看了下源码,应该是只处理以下: var KEYWORDS = // 关键字 'break,case,catch,continue,debugger,default,delete,do,else,false' + ',finally,for,function,if,in,instanceof,new,null,return,switch,this' + ',throw,true,try,typeof,var,void,while,with' // 保留字 + ',abstract,boolean,byte,char,class,const,double,enum,export,extends' + ',final,float,goto,implements,import,int,interface,long,native' + ',package,private,protected,public,short,static,super,synchronized' + ',throws,transient,volatile' // ECMA 5 - use strict + ',arguments,let,yield' + ',undefined';
解决方法3中
artTemplate是运行在沙箱里的默认不调用全局对象 有3种解决方法 1.数据转化在渲染前处理好, 2.注册在help中: template.helper('parseInt', parseInt); 3.把window作为数据传入 <%=global.parseInt(x)%> var data={global:window, x: '0'};