zoukankan      html  css  js  c++  java
  • 模板内部不支持原生js的方法?》》artTemplate模版方法注册window全部事件方法

    我的模板中出现了:
    {{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'};
    

      

    有时候不是我们失去了目标,而是失去了方向。
  • 相关阅读:
    rgba()与opacity的区别
    BFC 和 margin collapse(重叠)
    CSS面试题整理
    HTML面试题整理
    box-sizing 和calc()
    怎样用一个标签制作多边框的按钮?
    github项目配置
    React之JSX
    angularjs指令系统系列课程(5):控制器controller
    angularjs指令系统系列课程(4):作用域Scope
  • 原文地址:https://www.cnblogs.com/871735097-/p/5062646.html
Copyright © 2011-2022 走看看