Ext文档就是鸡肋。
在你不懂Ext的时候,这些文档很有帮助。当你已经很熟悉Ext想要使用一些高级功能时,你发现Ext文档很垃圾。比如,你找不到关于ColumnModel.renderer方法的详细信息。
看看文档的描述:
listeners : Object
(optional) A config object containing one or more event handlers to be added to this object during initialization. This should be a valid listeners config object as specified in the addListener example for attaching multiple handlers at once.
简直毫无意义。实际上,该方法接受6个参数:
renderer(value, cellmeta, record, rowIndex, columnIndex, store) {
}
再举一例,
addEvents( Object object ) : void
Used to define events on this Observable
Used to define events on this Observable
Parameters:
object : Object
The object with the events defined
Returns:
void
完全没有告诉大家该参数的可能形式,例如数组。另外,eventname不能是大小混合,系统接受大小写的事件名称,但默认转换成小写。可hasListener不处理大小写。
假设你添加了一个Event叫做addCriteria,系统认为该事件是addcriteria,但调用hasListener('addCriteria')返回false。
这是个bug。
看作者咋说:
Lowercase was the event standard for HTML. e.g.
node.onclick = ... not node.onClick = ...
It's also nice to prevent casing errors. Since it's just a string name, one wrong case can be impossible to detect and/or debug.
__________________
Jack Slocum
Ext JS - Core Development Team
[email protected]
如何修正该bug。
Observable.js
/**
* Checks to see if this object has any listeners for a specified event
* @param {String} eventName The name of the event to check for
* @return {Boolean} True if the event is being listened for, else false
*/
hasListener : function(eventName){
//var e = this.events[eventName];
var e = this.events[eventName.toLowerCase()];//正确代码
return typeof e == "object" && e.listeners.length > 0;
},
诸如此类的问题,太多太多。