javascript - Backbone this.el vs this.$el -
for given example, difference between this.el
& this.$el
i understand this.$el
points jquery object of this.el
, in case 'li'
.
when render view, can choose between this.el
, or this.$el
. how able render page when reference jquery object? can see how using this.$el.html(property)
, points html, why appending this.$el
, having render confuses me.
var person = backbone.model.extend({ defaults: { name: 'john doe', age: 30, occupation: 'worker' } }); var personview = backbone.view.extend({ tagname: 'li', initialize: function() { this.render(); }, render: function() { var out = this.$el.html(this.model.get('name') + this.model.get('occupation')); console.log(this, this.el, this.$el, out); $('body').append(this.$el); }, }); var person = new person; var personview = new personview({model: person});
bojangles correct.
this.$el
reference element in context of jquery, typically use things .html()
or .addclass()
, etc. example, if had div id somediv
, , set el
property of backbone view, following statements identical:
this.$el.html()
$("#somediv").html()
$(this.el).html()
this.el
native dom element, untouched jquery.
Comments
Post a Comment