| Package: | Ext.util |
| Class: | Observable |
| Extends: | Object |
| Subclasses: | BasicDialog , BasicLayoutRegion , Button , Component , ContentPanel , LayoutManager , Resizable , SplitBar , TabPanel , TabPanelItem , UpdateManager , View , Node , Store , Tree , BasicForm , AbstractSelectionModel , ColumnModel , Grid , Menu , DefaultSelectionModel , MultiSelectionModel , ClickRepeater , MixedCollection |
| Defined In: | Observable.js |
Employee = function(name){
this.name = name;
this.events = {
"fired" : true,
"quit" : true
}
}
Ext.extend(Employee, Ext.util.Observable);
| 方法 | 定义对象 | |
|---|---|---|
Observable.capture
(Observable o, Function fn, [Object scope]) : void |
Observable | |
| <static> 开始捕捉特定的Observable 对象。在事件触发之前, 所有的事件会以"事件名称+标准签名"的形式传入到指定的函数。 | ||
Observable.releaseCapture
(Observable o) : void |
Observable | |
| <static> 从 Observable 对象身上移除所有已加入的捕捉。 | ||
addEvents
(Object object) : void |
Observable | |
| 将对象中没有的事件从给出的对象中复制过来。 | ||
addListener
(String eventName, Function handler, [Object scope], [Object options]) : void |
Observable | |
| 为该组件加入事件处理器函数 | ||
fireEvent
(String eventName, Object... args) : Boolean |
Observable | |
| 触发指定的事件, 并将参数传入(至少要有事件名称)。 | ||
hasListener
(String eventName) : Boolean |
Observable | |
| 检查该对象是否拥有指定事件的侦听器 | ||
on
(String eventName, Function handler, [Object options]) : void |
Observable | |
| 为该组件加入事件处理器函数, addListener 的简写方式 | ||
| purgeListeners () : void | Observable | |
| 从对象身上移除所有的侦听器 | ||
removeListener
(String eventName, Function handler, [Object scope]) : void |
Observable | |
| 移除侦听器 | ||
un
(String eventName, Function handler, [Object scope]) : void |
Observable | |
| 移除侦听器, removeListener 的简写方式 | ||
public function Observable.capture(Observable o, Function fn, [Object scope])
o : Observable
fn : Function
scope : Object
voidpublic function Observable.releaseCapture(Observable o)
o : Observable
voidpublic function addEvents(Object object)
object : Object
voidpublic function addListener(String eventName, Function handler, [Object scope], [Object options])
eventName : String
handler : Function
scope : Object
options : Object
组合选项
使用选项参数可以组合不同类型的监听器:
下面是一个标准的、延迟执行的、一次性的监听器,将会自动停止事件并传递一个自定义的参数(forumId)
el.on('click', this.onClick, this, { single: true, delay: 100, stopEvent : true, forumId: 4 });
这个方法也允许传递的单个参数是一个包含多个指定处理函数的设置对象。
一次调用多个处理函数
代码:
el.on({ 'click' : { fn: this.onClick scope: this, delay: 100 }, 'mouseover' : { fn: this.onMouseOver scope: this }, 'mouseout' : { fn: this.onMouseOut scope: this } });
或者简写为:
代码:
el.on({ 'click' : this.onClick, 'mouseover' : this.onMouseOver, 'mouseout' : this.onMouseOut scope: this });
voidpublic function fireEvent(String eventName, Object... args)
eventName : String
args : Object...
Boolean
public function hasListener(String eventName)
eventName : String
Boolean
public function on(String eventName, Function handler, [Object options])
eventName : String
handler : Function
options : Object
voidpublic function purgeListeners()
voidpublic function removeListener(String eventName, Function handler, [Object scope])
eventName : String
handler : Function
scope : Object
voidpublic function un(String eventName, Function handler, [Object scope])
eventName : String
handler : Function
scope : Object
void