我正在使用Underscore.js来渲染html页面。
this.template = _.template($(templateName).html());
我在我的html页面中有这样的textarea。
<textarea id="description" name="description" rows="4"><%= typeof description == 'undefined' ? '' : description %></textarea>
在Underscore.js中,它会转到下面一行来替换desription内容。
if (interpolate) {
source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
}
现在,问题是textarea它会返回这样的结果..
<textarea id="description" name="description" rows="4">'+
((__t=( typeof description == 'undefined' ? '' : description ))==null?'':__t)+
'</textarea>
至于检查textarea的空值,我们不能使用null,我们必须使用''。所以如果不是条件,它会抛出else值'__t'
其他broeswers接受它并在textarea内部不显示任何内容。但是IE 10在textarea中显示了内容'[object HTMLMetaElement]'
。
答案 0 :(得分:1)
我得到了解决方案。
我又添加了一个修复它的条件。
替换此行
source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
在underscore.js中使用此行
source += "'+\n((__t=(" + interpolate + "))==null?'':((typeof __t == 'object' && JSON.stringify(__t) == '{}') ? '': __t))+\n'";