在Ember或JQuery中,$()是什么?

What is this.$() in Ember or JQuery

本文关键字:是什么 Ember JQuery      更新时间:2023-09-26

我在https://github.com/lukemelia/jquery-ui-ember上看到示例代码。$()

你可以在jquery-ui-ember-master'jquery-ui-ember-master'js'app.js

this.$()是当前objectscope的$方法的调用。

this是指当前对象。
$this的函数。
()将调用this$函数

当您创建Component时,在其代码this.$()中为您提供了一个jQuery对象引用,设置为该Component插入dom的元素(它的外部标记,通常是div,除非您另有说明)。然后,您可以使用例如this.$('.myclass')来查找由该Component处理的HTML部分中具有myclass类的元素,而不必指定id属性来查找正确的元素集。

这可能也适用于View s,但您应该尽可能使用Component

正如left所说,this.$()将为您提供对jQuery对象的引用,但通常您应该只希望在didInsertElement中获得对jQuery对象的引用,其中组件已插入到DOM中,并且您可以在元素上执行jQuery- ui内容