0

任何人都可以帮助我找到我们的问题,我的代码发生了什么..

我收到错误消息:

Uncaught SyntaxError: Unexpected token < 

我的代码在这里:

$(function() {

    var userDetails=[
        {firstName:'Lakshmi', lastName:'Narayanan',age:32},
        {firstName:'Harish', lastName:'Manickam',age:28},
        {firstName:'Madan', lastName:'Gopal',age:27}
    ]

    var userModel = Backbone.Model.extend({
        defaults:{
            firstName:"",
            lastName:"",
            age:""
        }
    });

    var userList = Backbone.Collection.extend({
        model:userModel
    });

    var userView = Backbone.View.extend({
        tagName:"tr",
        className:"userList",
        template: $("#listTempalate").html(),
        render:function(){
            var temp = _.template(this.template);
            this.$el.html(temp(this.model.toJSON()));
            return this;
        }
    });

    var usersView = Backbone.View.extend({
        el:"tbody",
        initialize:function(){
            this.collection = new userList(userDetails);
            this.render();
        },
        render:function(){
            var that = this;
            _.each(this.collection.models, function(item){
                that.$el.append(new userView({model:item}).render().el);
            })
        }
    });

    var Router = Backbone.Router.extend({
        routes:{
            '' : 'home'
        }
    });

    var router = new Router();
    router.on('route:home', function(){
        var defaultUser = new usersView();
    })

    Backbone.history.start();

});

我的 HTML:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,Chrome=1" />
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
    <title>User Manager</title>
    <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
</head>
<body>
    <div class="container">
        <h1>User Manager</h1>
        <hr>
        <div class="page">
            <table class="table striped">
                <thead>
                    <tr>
                        <th>First Name</th>
                        <th>Last Name</th>
                        <th>Age</th>
                        <th>Edit</th>
                    </tr>
                </thead>
                <tbody id="insertRows">

                </tbody>
            </table>
        </div>
    </div>
    <script id="listTempalate" type="text/template">
        <td><%= firstName %></td>
        <td><%= lastName %></td>
        <td><%= age %></td>
        <td><%= <a hre="#/edit/<%= user.id %>" class="btn">Edit</a></td>
    </script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js"></script>
    <script type="text/javascript" src="js/userManager.js"></script>
</body>
</html>

说真的,我无法在这里找到我的问题来解决它。以及任何人建议我在线查找backbone.js的问题..

所以让我继续检查我的代码..

提前致谢..

4

1 回答 1

2

很确定这与您的 HTML 中的这一行有关

<td><%= <a hre="#/edit/<%= user.id %>" class="btn">Edit</a></td>

您打开<%=然后再次打开它/edit/<%=,我认为这是导致问题的原因。即使允许打开它两次,您也没有%>在该行中添加一个final。

玩弄它,让我们知道它是怎么回事。

编辑

试试这个

<td> <a href="#/edit/<%= user.id %>" class="btn">Edit</a></td>

您不需要将整个内容包装在<%and%>标记中,只需要将您想要输出的部分包装起来。

于 2013-04-25T14:17:52.707 回答