javascript 停止来自 Ember 操作的点击传播?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22230430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 22:44:00  来源:igfitidea点击:

Stop click propagation from Ember action?

javascriptviewember.jsclick

提问by Jaime

I have this code that when icon-edit span is clicked, it fires an action that opens a modal, however, at the same time, the click propagates to the view below it (personView). I want the action to execute and stop the propagation.

我有这样的代码,当单击 icon-edit span 时,它会触发一个打开模态的操作,但是,与此同时,点击会传播到它下面的视图 (personView)。我希望该操作执行并停止传播。

The only solution I can think of is to make the icon-edit its own view and stop the click propagation by returning false in method click. Is there any other way of doing this without making another view?

我能想到的唯一解决方案是让图标编辑它自己的视图并通过在方法 click 中返回 false 来停止点击传播。有没有其他方法可以做到这一点而不提出另一种观点?

HBS:

哈佛商学院:

{{#view Blocks.PersonView}}
  <span class="inline pull-right icon-edit" {{action 'modalOpen' 'modifyPersonPopup' 'modifyPerson' this}}></span>
  <p class="inline pull-left person-name">{{firstNameDelayed}}</p>
{{/view}}

回答by undeletable

Also you can add bubbles=falseparameter to actiontag. See the API documentationfor how to configure event propagation.

您也可以bubbles=falseaction标签添加参数。有关如何配置事件传播的信息,请参阅API 文档

回答by undeletable

Try to modify the action:

尝试修改动作:

modalOpen: function {
    //code of your action
    return false;    
}

This worked for me in a similar situation

这在类似的情况下对我有用