我有了主心骨/下划线应用程序通过require.js运行underscore.js - 对象不支持此属性或方法 - IE8
我刚才一直在做一些跨浏览器上我的应用程序检查,并认识到我的应用程序在加载ie8中的模板时遇到问题。
我的应用程序中,当渲染功能运行加载和在正确的模板调用
然后我用_.template转换代码视图部分内。
所以内作出我把这种
$t.$el.append($t.renderTemplate(data, templateVars));
数据是在<%=%>格式和templateVars的HTML是renderTemplate其返回的数据(通常JSON结果)对象
的列表函数看起来像
renderTemplate: function(html, vars) {
var compiled = _.template(html);
console.log(compiled, "compiled");
return compiled(vars);
},
的问题是,在IE8我得到一个错误是
对象不支持此属性或方法
这是它从该代码
_.template = function(text, data, settings) {
settings = _.extend(_.templateSettings, settings);
// Compile the template source, taking care to escape characters that
// cannot be included in a string literal and then unescape them in code
// blocks.
var source = "__p+='" + text
.replace(escaper, function(match) {
return '\\' + escapes[match];
})
.replace(settings.escape || noMatch, function(match, code) {
return "'+\n_.escape(" + unescape(code) + ")+\n'";
})
.replace(settings.interpolate || noMatch, function(match, code) {
return "'+\n(" + unescape(code) + ")+\n'";
})
.replace(settings.evaluate || noMatch, function(match, code) {
return "';\n" + unescape(code) + "\n;__p+='";
}) + "';\n";
// If a variable is not specified, place data values in local scope.
if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
source = "var __p='';" +
"var print=function(){__p+=Array.prototype.join.call(arguments, '')};\n" +
source + "return __p;\n";
var render = new Function(settings.variable || 'obj', '_', source);
if (data) return render(data, _);
var template = function(data) {
return render.call(this, data, _);
};
// Provide the compiled function source as a convenience for build time
// precompilation.
template.source = 'function(' + (settings.variable || 'obj') + '){\n' +
source + '}';
return template;
};
// Add a "chain" function, which will delegate to the wrapper.
_.chain = function(obj) {
return _(obj).chain();
};
这是代码FF /铬用来转换示数列于
return render.call(this, data, _);
线传回模板
// Add a "chain" function, which will delegate to the wrapper.
_.chain = function(obj) {
return _(obj).chain();
};
Und erscore.js 1.3.2
能正常工作在IE9,FF和铬
谁能帮助?
是否设置了文档类型? – inf3rno
其设置像 - <!DOCTYPE html> - 是好的 – Dan
它可以导致javascript问题,因为ie8不知道html5。我不知道这个设置会选择哪种文档模式...在MSIE运行javascript代码高度依赖于当前文档模式...我需要进一步调查,可悲的是我现在无法测试MSIE8 ...: S – inf3rno