BackboneJs: In a view whats the difference between el: and tagName:

后端 未结 2 1082
囚心锁ツ
囚心锁ツ 2021-02-04 05:51

I\'m trying to wrap my head around this concept.

Can you dumb this down for me and maybe provide a simple example of the difference between the el: attribu

2条回答
  •  太阳男子
    2021-02-04 06:36

    var View = Backbone.View.extend({
      tagName: 'span',
      id: 'identity',
      class: 'classy',
      el: $(this.tagName), // or
      el: $('<' + this.tagName + ' />', {
        id: this.id,       // identity
        'class': this.class  // classy
      })  // this is jQuery shorthand for building an element fyi
    });
    
    var view = new View();
    

    I think that should work fine.

提交回复
热议问题