2012-04-18 39 views
2

我試圖得到一個Ember.View聽由CONTENTEDITABLE元素觸發的事件,但我有一個小麻煩。Ember.View CONTENTEDITABLE事件

最終的結果我去了是有必然灰燼對象屬性CONTENTEDITABLE變化。這對Ember.View指定contenteditable change events

$(function() { 
    $(document).on('focus', '[contenteditable]', function(event) { 
    var $this = $(this); 
    console.log("$" + event.type); 
    return $this; 
    }); 
    $(document).on('blur keyup paste', '[contenteditable]', function(event) { 
    var $this = $(this); 
    console.log("$" + event.type); 
    return $this; 
    }); 
}); 

但事件處理程序永遠不會叫:

App.ContentEditable = Ember.View.extend({ 
    item: App.Item.create({name:"Editable content"}), 
    tagName: "span", 
    contenteditable:"true", 
    attributeBindings: ["contenteditable"], 

    // Only event that gets triggered 
    click: function(){ console.log("click") }, 

    // None of these events are triggered 
    focusin: function(){ console.log("focusin") }, 
    focusout: function(){ console.log("focusout") }, 
    keyup: function(){ console.log("keyup") }, 
    blur: function(){ console.log("blur") }, 
    paste: function(){ console.log("paste") }, 
});​ 

我已經把

活動正在使用jQuery直接在這個答案給出正確綁定在一起的jsfiddle顯示該.on()事件記錄到控制檯,但是,Ember.View的事件不是:http://jsfiddle.net/chrisconley/RqSn4/

回答

2

這是因爲在灰燼事件名稱被翻譯爲更多的灰燼般的命名約定。這個東西發生在packages/ember-views/lib/system/event_dispatcher.js。正如你所看到的,你有你的現有的事件處理程序命名爲keyUpfocusInfocusOut

其他事件blurpaste默認情況下不處理,那是什麼customEventsEmber.Application是,看http://jsfiddle.net/pangratz666/CHVRt/

App = Ember.Application.create({ 
    customEvents: { 
     blur: 'blur', 
     paste: 'paste' 
    } 
}); 
+0

非常感謝 - 想通這是一些愚蠢的。並感謝有關customEvents的提示! – 2012-04-18 16:37:06

+0

很高興我能幫到你。我還沒有找到一個關於emberjs.com這個命名,文件翻譯,所以我想這應該是固定的。 – pangratz 2012-04-18 16:39:20

相關問題