someObject.$()
是什么意思?
我正在浏览sapui5工具包中的tilecontainer-dbg文件并发现:
var oDomRef = this.$();
or someObject.$()
答案 0 :(得分:3)
$
只是javascript中的合法符号。因此,this.$()
或someObject.$()
只是对该对象的方法调用。该对象有一个名为$
的属性,它是一个函数(例如方法)。
这是一个例子:
var obj = {
"data": 3,
"$": function() {
return this.data;
}
};
var val = obj.$(); // returns 3
答案 1 :(得分:2)
在SAPUI5中,$& jQuery是用于访问jQuery功能的全局变量
this.$() is similar to jQuery('#this.sId')
or
document.getElementById(this.sId)
返回表示此Element包装为jQuery对象的最合适的DOM节点。
下面是代码定义
/**
* Returns the best suitable DOM node that represents this Element wrapped as jQuery object.
* I.e. the element returned by {@link sap.ui.core.Element#getDomRef} is wrapped and returned.
*
* If an ID suffix is given, the ID of this Element is concatenated with the suffix
* (separated by a single dash) and the DOM node with that compound ID will be wrapped by jQuery.
* This matches the UI5 naming convention for named inner DOM nodes of a control.
*
* @param {string} [sSuffix] ID suffix to get a jQuery object for
* @return {jQuery} The jQuery wrapped element's DOM reference
* @protected
*/
sap.ui.core.Element.prototype.$ = function(sSuffix) {
return jQuery(this.getDomRef(sSuffix));
};