是的,这是正确的。
chaplinjs能够监听以下方法:
var MyView = Chaplin.View.extend({
events: {
// Listen to $ DOM events
'click button': 'methodName',
'change select#myid': 'methodName',
...
},
listen: {
// Listen to Chaplin events
'onAddedToDOM': 'methodName',
...
// Listen to model events
'change:foo model': 'methodName',
// Listen to collection events
'reset collection': 'methodName',
// Custom mediator events (or Chaplin events, like router:route etc.)
'pubSubEvent mediator': 'methodName',
// The value can also be a function.
'eventName': function() {alert('Hello!')}
},
使用mediator
该类,通过受控渠道发布/或订阅直接通信:
this.publishEvent('pubSubEvent', ['Joe', 'Schmoe']);
或在您的视野之外:
require('chaplin');
Chaplin.mediator.publishEvent('pubSubEvent', ['Joe', 'Schmoe']);
您可以在此处找到事件委托的源代码:https ://github.com/chaplinjs/chaplin/blob/master/src/chaplin/views/view.coffee#L299-308