mrp*_*rpx 6 javascript events dojo
我正在使用Dojo框架来帮助我在Javascript开发中使用交叉浏览DOM操作和事件管理.
为此,我希望在对象之间使用自定义事件调度.但我没有发现任何相关内容.我读到了订阅/发布,但这不完全是我想要的.
这是我想要做的:
var myObject = new CustomObject();
dojo.connect(myObject, 'onCustomEvent', function(argument) {
console.log('custom event fired with argument : ' + argument);
});
var CustomObject = (function() {
CustomObject = function() {
// Something which should look like this
dojo.dispatch(this, 'onCustomEvent', argument);
};
}) ();
Run Code Online (Sandbox Code Playgroud)
有人可以帮帮我吗?
谢谢.
小智 3
我通常这样做:(用Dojo 1.3.2测试)
dojo.declare("CustomObject", null, {
randomFunction: function() {
// do some processing
// raise event
this.onCustomEvent('Random Argument');
},
onCustomEvent: function(arg) {
}
});
var myObject = new CustomObject();
dojo.connect(myObject, 'onCustomEvent', function(argument) {
console.log('custom event fired with argument : ' + argument);
});
// invoke the function which will raise the custom event
myObject.randomFunction();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2706 次 |
| 最近记录: |