【问题标题】:Backbone - this.$el vs $(this.el)?骨干网 - this.$el vs $(this.el)?
【发布时间】:2013-09-25 19:26:52
【问题描述】:

我一直在我的主干应用程序中使用this.$el,如下所示:

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

然后我在网上看到代码使用:

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

两者有什么区别?

【问题讨论】:

  • 文档非常清楚 $el 是什么。使用$(this.el)的人在过去学习过Backbone(或者从基于旧版本的教程中学习),仅此而已。

标签: javascript jquery backbone.js el


【解决方案1】:

如果您调用 $(this.el),您只需继续执行 jquery selector 即可获得相同的 jquery 对象。 '$el' 是 $(this.el) 的缓存版本

【讨论】:

    猜你喜欢
    • 2012-09-22
    • 2016-05-08
    • 1970-01-01
    • 1970-01-01
    • 2013-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多