Ember.js Ember.Instrumentation.subscribe:来自把手的触发事件

Ember.js Ember.Instrumentation.subscribe:来自把手的触发事件,ember.js,Ember.js,在视图的init中,我将事件侦听设置为: Ember.Instrumentation.subscribe("inlineEdit.makeBlue", { before: function (name, timestamp, payload) { alert(name, timestamp,payload); }, after: function () { } }); 在车把上,我想用一个动作来触发事件: <a {{action in

在视图的init中,我将事件侦听设置为:

 Ember.Instrumentation.subscribe("inlineEdit.makeBlue", {
    before: function (name, timestamp, payload) {
       alert(name, timestamp,payload);
    },
    after: function () {

    }
  });
在车把上,我想用一个动作来触发事件:

<a {{action inlineEdit.makeBlue on="mouseDown"}} class="btn ">Blue</a>
蓝色

不幸的是,这不会触发上述事件侦听器。仪表事件是否可以从把手触发?如果是,怎么做

目前在ember core中不可用,但可以实现

当您在内部使用操作时,ember将使用
ember.ActionHandler#send
方法分派这些事件。因此,您可以重新打开该类并代理该方法,将调用包装在
Ember.instrument

Ember.ActionHandler.reopen({
    send: function(actionName) {
        var orininalArguments = arguments, 
            args = [].slice.call(arguments, 1), 
            result;        
        Ember.instrument('action.' + actionName, args, function() {            
            result = this._super.apply(this, orininalArguments);
        }, this);        
        return result;
    }
});
因此,您可以订阅:

// Specific action
Ember.Instrumentation.subscribe("action.inlineEdit.makeBlue", { ... })
我在订阅中添加了
action
前缀,因此您可以利用instrumentation api,并通过以下方式侦听所有操作事件:

// All actions
Ember.Instrumentation.subscribe("action", { ... })
看看那把小提琴,看看它能不能用


我希望它有帮助

目前在ember core中不可用,但可以实现

当您在内部使用操作时,ember将使用
ember.ActionHandler#send
方法分派这些事件。因此,您可以重新打开该类并代理该方法,将调用包装在
Ember.instrument

Ember.ActionHandler.reopen({
    send: function(actionName) {
        var orininalArguments = arguments, 
            args = [].slice.call(arguments, 1), 
            result;        
        Ember.instrument('action.' + actionName, args, function() {            
            result = this._super.apply(this, orininalArguments);
        }, this);        
        return result;
    }
});
因此,您可以订阅:

// Specific action
Ember.Instrumentation.subscribe("action.inlineEdit.makeBlue", { ... })
我在订阅中添加了
action
前缀,因此您可以利用instrumentation api,并通过以下方式侦听所有操作事件:

// All actions
Ember.Instrumentation.subscribe("action", { ... })
看看那把小提琴,看看它能不能用

我希望有帮助