0

我在使用这两种浏览器Backbone.js,并且Underscore.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: [
        .....
        ]
    }
];

请帮助我知道我在哪里做错了。

4

1 回答 1

1

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

于 2013-02-06T11:09:48.530 回答