【问题标题】:Error when printing a null in dojo dtl在 dojo dtl 中打印空值时出错
【发布时间】:2013-10-09 07:06:43
【问题描述】:

我有一个用 Dojo 编写的基本小部件,它使用 DTL 来打印几个变量。但是,当其中一个变量为空时,会导致错误(str 为空)。是否可以解决或绕过此错误?我希望它只打印一个空字符串...

我在 Firefox 24 中使用 dojo 1.9.0。

【问题讨论】:

  • 欢迎来到 StackOverflow。你有一些我们可以看到的代码吗?没有代码我们很难帮你。

标签: javascript dojo django-templates


【解决方案1】:

我遇到了同样的问题,我最终创建了一个补丁,这样就不会发生这种情况。 这将返回字符串 null。如果您希望它返回空刺,请取消注释 str="";

//Patch for DTL so it wont fail everytime there is a null value in JSON.
    require([ "dojox/dtl/_base"],function(){
        dojox.dtl._VarNode.prototype.render = function(context, buffer){
            var str = this.contents.resolve(context);
            if(str){
                if(!str.safe){
                    str = dojox.dtl._base.escape("" + str);
                }
            }else{
                writeLog("=====Value was Null::" + this.contents.key);
                //str="";
            }
            return buffer.concat(str);
        };
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-03
    • 2021-06-11
    • 1970-01-01
    • 1970-01-01
    • 2020-08-10
    • 1970-01-01
    相关资源
    最近更新 更多