backbone.js - My JavaScript code throws a SyntaxError (Unexpected token <) -
any 1 me find our issue, going on code..
i getting error :
uncaught syntaxerror: unexpected token <
my code here :
$(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 = 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(); });
my 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>
seriously unable find issue here fix it. 1 suggest me find issue backbone.js online..
so let me keep check code..
thanks in advance..
pretty sure line in html
<td><%= <a hre="#/edit/<%= user.id %>" class="btn">edit</a></td>
you open <%=
, open again /edit/<%=
think causing problem. if opening twice allowed, haven't added final %>
line.
play around , let know how goes.
edit
try instead
<td> <a href="#/edit/<%= user.id %>" class="btn">edit</a></td>
you shouldn't need wrap entire thing in <%
, %>
tags, part want output.