jQuery 实现观察者模式
2017-02-17 18:11
387 查看
github:
demo:
https://github.com/mmikowski/jquery.event.gevent
demo:
$('body').append( "<div id='spa-chat-list-box' />" ); var $listbox = $('#spa-chat-list-box'); $listbox.css({ position : "absolute", 'z-index' : "3", top : "50", left : "50", width : "50", height : "50", border : "2px solid #ccc", background : "#fff", }) var onListchange = function ( event, update_map ){ $( this ).html(update_map.list_text); alert("onListchange"); } /* 订阅事件 */ $.gevent.subscribe( $listbox, 'spa-listchange', onListchange ); /* 发布通知 */ $.gevent.publish( 'spa-listchange', [{ list_text : 'the list is here'}] ); /* 删除元素的话,订阅的事件也会删除 */ $listbox.remove(); $.gevent.publish('spa-listchange',[ { } ]);
相关文章推荐
- 设计模式之观察者模式(订阅模式),jquery实现
- .net中的观察者模式(用delegate/event实现)
- Observer Pattern(观察者模式)及其在C#中的实现
- 观察全世界(观察者模式的可复用代码实现)(下)
- AspectJ实现设计模式(一)——观察者模式
- 传统javascript事件模型实现观察者模式
- 设计模式PHP5实现之----观察者(Observer)
- 学习设计模式之旅 / 观察者(Observers)委托实现.. 推荐
- Flash/Flex/AIR:ActionScript 2定时器--基于观察者模式的实现
- 使用观察者模式实现Java应用程序设计MVC模式
- 用C#委托实现哨兵和敌人的观察者模式!
- 用 spring 实现观察者设计模式
- 利用委托实现观察者模式
- 用AOP实现观察者模式
- 观察全世界(观察者模式的可复用代码实现)(上)
- 用spring实现观察者设计模式
- C#中利用代理实现观察者设计模式
- 如何使用委托与事件来实现观察者模式
- 在asp.net中实现观察者模式,或有更好的办法?
- 观察者模式实现1