使用underscore.js的模板渲染在IE8中不起作用

时间:2013-02-06 10:38:36

标签: javascript jquery templates backbone.js underscore.js

我正在使用Backbone.jsUnderscore.js 它在所有其他浏览器中工作正常,包括IE9但是 我在 IE8

中出现此错误
SCRIPT1010: Expected identifier 
underscore.js, line 1156 character 7

以下是我收到错误的代码

模板

<script type="text/template" id="maps-template">
    <% _.each(data, function(d) { %>
        <map id="<%= d.for %>" name="<%= d.for %>">
            <% _.each(d.area, function(d) { %>
                <area shape="<%= d.shape %>" alt="<%= d.alt %>" title="<%= d.title %>" coords="<%= d.coords %>" href="<%= d.href %>" target="_blank" />
            <% });  %>
        </map>
    <% });  %>
</script>

模板渲染

pc.ui.Maps = Backbone.View.extend({
    initialize: function() {
        this.render();
    },
    render: function() {
        var template = _.template($("#maps-template").html(), {data: pc.products.maps});
        $('body').append(template);
        return this;
    }
});

var view = new pc.ui.Maps();

其中pc.products.maps是一个对象数组,如下所示

pc.products.maps = [
    {
        for: "dept_a",
        area: [
            {
                coords: '426,136,618,173',
                shape: 'rect',
                href: 'example.com',
                title: '',
                alt: ''
            },
            {
                coords: '427,156,718,173',
                shape: 'rect',
                href: 'example.com',
                title: '',
                alt: ''
            },
            {
                coords: '428,186,818,173',
                shape: 'rect',
                href: 'example.com',
                title: '',
                alt: ''
            }
        ]
    },
    {
        for: 'dept_b',
        area: [
        .....
        ]
    }
];

Plz帮助我知道我做错了什么。

1 个答案:

答案 0 :(得分:1)

我只是在猜测,也许for是一个保留字?尝试将它放在对象数组中的双引号中,例如"for" : 'dept_b'或只更改该属性名称。