骨干 - 这个。$ el vs $(this.el)? [英] Backbone - this.$el vs $(this.el)?

查看:95
本文介绍了骨干 - 这个。$ el vs $(this.el)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用这个。$ el 遍布我的骨干应用程序,如下所示:

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);
}

这两者有什么区别?

推荐答案

如果你打电话给$(this.el),你就继续执行 jquery选择器以获取相同的jquery对象。 '$ el'是$(this.el)

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)

这篇关于骨干 - 这个。$ el vs $(this.el)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆