1

I am a newer for backbone. There is a link for my code.

$(function (){
  var test = {};
    test.View = Backbone.View.extend({
        el: 'body',
        initialize: function (){
            this.input = $('#new-todo');
        },
        events: {
            'keyup #new-todo': 'check'
        },
        check: function (){
      console.log('!');
            $('#test').html(this.input.val());
        }
    });
    test.view = new test.View();
});

I found a similar question but still confused it.When I set el:'#container' the keyup event doesn't work.

I want to know, what is it the View.el, what's is that its function? What's the different from el: 'body' and el: '#container'.

Community
  • 1
  • 1
Todd Mark
  • 1,847
  • 13
  • 25

1 Answers1

1

Backbone expects the view to only handle the events within it's specific DOM element(el). Your #new-todo is outside #container

I want to know, what is it the View.el, what's is that its function? What's the different from el: 'body' and el: '#container'.

el is the element the view refers to all the time. The events are attached to elements within this el element.

Think for it this way: The view only refers to el element.

Ajay Narain Mathur
  • 5,326
  • 2
  • 20
  • 32
  • 1
    http://backbonejs.org/#View I read the document again and think over your answer **only handle the events within it's specific DOM**. I understand the `view.el`. It's a range like a scope of function. All the elements events could be fired by the `view.el`. Thanks for your help :) – Todd Mark Jun 28 '15 at 11:39