我有一个用 Dojo 编写的基本小部件,它使用 DTL 来打印几个变量。但是,当其中一个变量为空时,会导致错误(str 为空)。是否可以解决或绕过此错误?我希望它只打印一个空字符串...
我在 Firefox 24 中使用 dojo 1.9.0。
我有一个用 Dojo 编写的基本小部件,它使用 DTL 来打印几个变量。但是,当其中一个变量为空时,会导致错误(str 为空)。是否可以解决或绕过此错误?我希望它只打印一个空字符串...
我在 Firefox 24 中使用 dojo 1.9.0。
我有同样的问题,我最终创建了一个补丁,所以这不会发生。这将返回字符串 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);
};
});