[英]Prevent click into {{input}} component from propagating/bubbling up (ember)
我在本身具有動作的元素內部有一個{{input}}
。
如何防止單擊輸入觸發父元素上的click事件?
bubbles=false
。 {{input}}
,在擴展輸入中,我捕獲了click事件,並稱為event.preventDefault()
請嘗試我的測試用例 : https : //ember-twiddle.com/a2cee9abd63a7400124e2745a7820cf8?numColumns=2&openFiles=controllers.application.js%2Ctemplates.application.hbs
hbs示例:
<div {{action "alert"}}> I don't want the click into the input to trigger the div's onlick. Help!<br/> {{input bubbles=false}} </div>
定義組件,例如my-input
,它擴展Ember.TextField
並定義click
函數,並return false
以防止冒泡。
import Ember from 'ember';
export default Ember.TextField.extend({
click(){
console.log('click my input');
return false;
}
});
對於my-input組件,在包含該組件時,您無需定義任何處理click事件的操作。 您可以說{{my-input }}
這是工作中的瑣事
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.