【发布时间】:2014-05-05 13:25:48
【问题描述】:
我不明白为什么我的模板不能在 IE(任何版本)中工作
模板
<div id="Hero-Right">
<script type="text/html" id="heroItems">
{{ _.each( planet.heroItems, function( heroItem ){ }}
<div class="item first">
img src="{{= heroItem.image }}" />
<div class="item-text">
{{= heroItem.text }}
</div>
</div>
{{ }); }}
</script>
</div>
我的数据是
var data = {
heroItems: [
{
image: "Images/Top-TV.png",
text: "Watch the Tv Show"
},
{
image: "Images/Top-Broc.png",
text: "The Brand"
}
]
}
为了渲染模板,我调用了函数
function renderTemplate(data) {
var template = _.template(
$("#heroItems").html()
);
$("#Hero-Right").html(
template(data)
);
};
为了使用小胡子分隔符,我更改了下划线分隔符
_.templateSettings = {
interpolate: /\{\{=(.+?)\}\}/g,
evaluate: /\{\{(.+?)\}\}/g,
};
这在 chrome 中显示得很好。
【问题讨论】:
-
那么在 IE 中会发生什么?您是否在开发者控制台中看到错误?
-
变量
planet是哪里来的?你能发布一个完整的jsfiddle吗? -
抱歉,我在 IE 中没有看到任何错误。
-
好的,是不是让你说它不起作用?你能想象为什么这些信息会对试图帮助解决问题的人有用吗?
-
您在模板中有错字,缺少带有图片标签的
<。
标签: javascript jquery templates underscore.js