简体   繁体   English

Backbone.Js - el和$ el之间有什么区别?

[英]Backbone.Js - what's the difference between el and $el?

So I've been stuck for the whole afternoon on this problem which I eventually solved. 所以我整个下午都陷入了这个问题 ,我最终解决了这个问题 It turned out I was assigning el instead of $el. 事实证明我指的是el而不是$ el。

What's the difference between the two and when should I use each of them? 这两者之间的区别是什么?我应该何时使用它们?

Straight from the documentation , $el is: 直接从文档中$el是:

A cached jQuery (or Zepto) object for the view's element. 视图元素的缓存jQuery(或Zepto)对象。 A handy reference instead of re-wrapping the DOM element all the time. 一个方便的引用,而不是一直重新包装DOM元素。

So, $el is a cached, jQuery (or Zepto) version of el . 所以, $el是一个高速缓存,jQuery的(或的Zepto)版本el If you need to use any jQuery or Zepto methods on el , you can simply use $el instead of wrapping el in $() each time. 如果你需要在el上使用任何jQuery或Zepto方法,你可以简单地使用$el而不是每次在$()中包装el

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM