Setting id and className dynamically in Backbone.js views

后端 未结 8 1823
生来不讨喜
生来不讨喜 2021-01-29 19:24

I am in process of learning and using Backbone.js.

I have an Item model and a corresponding Item view. Each model instance has item_class and item_id attributes, that I

8条回答
  •  故里飘歌
    2021-01-29 20:15

    You need to remove tagName and declare an el.

    'tagName' signifies that you want backbone to create an element. If the element already exists in the DOM, you can specify an el like:

    el: $('#emotions'),
    

    and later:

    render: function() { 
         $(this.el).append(this.model.toJSON());
    }
    

提交回复
热议问题