简体   繁体   English

如何取消 YUI DataTable 中的事件冒泡?

[英]How do I cancel event bubbling in a YUI DataTable?

I am trying to create a YUI 2.8.1 DataTable with a checkbox column.我正在尝试创建一个带有复选框列的 YUI 2.8.1 DataTable。 When the user selects the row it should highlight, but not when the user checks the checkbox.当用户选择它应该突出显示的行时,而不是当用户选中复选框时。

I'm trying to suppress the rowClickEvent by setting cancelBubble = true in the checkboxClickEvent, but the YUI library ignores this.我试图通过在 checkboxClickEvent 中设置cancelBubble = true来抑制 rowClickEvent,但 YUI 库忽略了这一点。 How do I prevent the rowClickEvent from firing?如何防止 rowClickEvent 触发?

this.testDataTable.subscribe("checkboxClickEvent", function (oArgs)
{
    var elCheckbox = oArgs.target;
    var oRecord = this.getRecord(elCheckbox);
    oRecord.setData("check", elCheckbox.checked);
    oArgs.event.cancelBubble = true; //Event bubbles anyway
});

return false from the checkboxClickEvent从 checkboxClickEvent 返回 false

I've worked around the issue by setting a flag to suppress row click, but I'd still like to know how to cancel the bubble "properly."我已经通过设置一个标志来抑制行点击来解决这个问题,但我仍然想知道如何“正确”取消气泡。

suppressHighlight = false;

this.testDataTable.onEventRowClick = function (oArgs)
{
    ...

    if (!suppressHighlight)
    {
        ...
    }
    suppressHighlight = false;
};
this.testDataTable.subscribe("rowClickEvent", this.testDataTable.onEventRowClick);

this.testDataTable.subscribe("checkboxClickEvent", function (oArgs)
{
    var elCheckbox = oArgs.target;
    var oRecord = this.getRecord(elCheckbox);
    oRecord.setData("Check", elCheckbox.checked);

    suppressHighlight = true;
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM