Noa*_*tas 19 javascript jquery this ember.js
在Ember.js的文档中,他们有一个jQuery代码片段,其语法如下:
this.$().button();
Run Code Online (Sandbox Code Playgroud)
这个片段只是变成this
了一个jQuery对象,以便.button()
可以在它上面调用jQuery UI 函数吗?
这个片段是否相同?
$(this).button();
Run Code Online (Sandbox Code Playgroud)
Esa*_*ija 26
该源代码解释此如下:
/**
Returns a jQuery object for this view's element. If you pass in a selector
string, this method will return a jQuery object, using the current element
as its buffer.
For example, calling `view.$('li')` will return a jQuery object containing
all of the `li` elements inside the DOM element of this view.
@param {String} [selector] a jQuery-compatible selector string
@returns {Ember.CoreQuery} the CoreQuery object for the DOM node
*/
$: function(sel) {
return this.invokeForState('$', sel);
},
Run Code Online (Sandbox Code Playgroud)
所以回答你的问题:不$(this)
,它会将ember视图实例包装在jQuery对象中...