Polarize
Polarize

Reputation: 1045

Unexpected Token "." (period)

I am starting to learn Backbone, but UnderscoreJS seems to be giving me some issues here. I am getting "Unexpected Token ." and I am not sure what that means. My JSON seems fine, so I am not expecting it to be a cause.

var Items = Backbone.Collection.extend({
  url: 'http://welfordian.com/backbone/data/items'
});
var ToDoList = Backbone.View.extend({
  el: '.page',
  render: function() {
    var items = new Items();
    var elem = this;
    items.fetch({
      success: function(items) {
        var template = _.template($('#todo-list-content').html(), {
          items: items.models
        });
        elem.$el.html(template);
      }
    });
  }
});
var Router = Backbone.Router.extend({
  routes: {
    '': 'index',
    'completed': 'completed'
  }
});

var toDo = new ToDoList({});
var router = new Router();
router.on("route:index", function() {
  toDo.render();
});
Backbone.history.start();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.3/backbone-min.js"></script>

<div class="page"></div>
<script type="text/html" id="todo-list-content">
  <table>
    <thead>
      <tr>
        <th>ID</th>
        <th>Description</th>
        <th>State</th>
      </tr>
    </thead>
    <tbody>
      <% ._each(items, function(item){ %>
        <tr>
          <td>Hello</td>
        </tr>
        <% }); %>
    </tbody>
  </table>
</script>

Upvotes: 1

Views: 2718

Answers (1)

Tushar
Tushar

Reputation: 87233

The syntax of the each in the template is not correct.

Change

._each(items, function(item){
^^

to

_.each(items, function(item) {

Upvotes: 3

Related Questions