模板内部不支持原生js的方法?》》artTemplate模版方法注册window全部事件方法

本文详细解释了在artTemplate中遇到的parseInt函数无法直接使用的问题,并提供了三种解决方案:数据预处理、注册自定义帮助函数和将全局对象作为数据传入。这为开发者在模板引擎中处理数字类型的数据提供了有效指导。
我的模板中出现了:
{{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'};

  

转载于:https://www.cnblogs.com/871735097-/p/5062646.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值