javascript SAPUI5:正确处理点击事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28187804/
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
SAPUI5: Handle click events properly
提问by AntonSack
I am using the SAPUI5 control GenericTile and added both headerImage and click event. When this icon is clicked, the event handler of the tile is triggered first so that I am not able to react on the icon click itself (which should perform another action of course).
我正在使用 SAPUI5 控件 GenericTile 并添加了 headerImage 和 click 事件。单击此图标时,首先触发 tile 的事件处理程序,因此我无法对图标单击本身做出反应(当然应该执行另一个操作)。
var oGenericTile = new sap.suite.ui.commons.GenericTile({
frameType: "TwoByOne",
header: "My HEader",
headerImage: "sap-icon://settings",
tileContent: oTileContent
});
oGenericTile._oImage.attachPress(function(oEvent) {
sap.m.MessageToast.show("Icon has been pressed");
oEvent.cancelBubble();
oEvent.preventDefault();
});
oGenericTile.attachPress(function() {
sap.m.MessageToast.show("I am always triggered first!!! :-(");
});`
Any idea how I can avoid this?
知道如何避免这种情况吗?
Thanks a ton,
万分感谢,
Anton
安东
采纳答案by 10littleOrcs
you could e.g. also cancel the event on the tile manually in order to avoid this behavior... you'd just need to track whether the icon has been pressed, see a simplified example on JSBin: http://jsbin.com/daqifomoge/3/edit
例如,您也可以手动取消磁贴上的事件以避免这种行为……您只需要跟踪图标是否已被按下,请参阅 JSBin 上的简化示例:http: //jsbin.com/daqifomoge /3/编辑
Extending existing controls and overriding methods always bears the potential to break things when the original control gets an update from the developers...
当原始控件从开发人员那里得到更新时,扩展现有控件和覆盖方法总是有可能破坏事物......
Maybe there's a more elegant way to do it, though.
不过,也许有一种更优雅的方式来做到这一点。
Best, Christiane
最好的,克里斯蒂安