Backbone - this.$el vs $(this.el)?

故事扮演 提交于 2019-12-22 10:40:05

问题


I've been using this.$el all over my backbone app like so:

render: function() {
    this.$el.html(this.template);
},

then I saw code online that uses:

render: function() {
    var dict = this.model.toJSON();
    var html = this.template(dict);
    $(this.el).append(html);
}

What is the difference between the two?


回答1:


If you call $(this.el), your just keep executing the jquery selector to get the same jquery object. '$el' is the cached version of $(this.el)



来源:https://stackoverflow.com/questions/19013531/backbone-this-el-vs-this-el

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!