在Ember.js的docs中,他们有一个jQuery代码片段,其语法如下:
this.$().button();
此代码段是否仅将this
转换为jQuery对象,以便可以在其上调用jQuery UI .button()
函数?
这段代码是否相同?
$(this).button();
答案 0 :(得分:26)
source code解释如下:
/**
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);
},
所以回答你的问题:不,它与$(this)
不一样,它会将ember视图实例包装在jQuery对象中......