简体   繁体   English

IE9 +的Telerik RadTreeView OnClientNodeChecked兼容性问题

[英]Telerik RadTreeView OnClientNodeChecked Compatibility issue with IE9+

I have a RadTreeView with dynamic levels and checkable nodes based on conditions. 我有一个RadTreeView,具有动态级别和基于条件的可检查节点。 Some levels may have no checkable nodes, some checkable nodes or all checkable nodes. 某些级别可能没有可检查的节点,某些可检查的节点或所有可检查的节点。

I use the OnClientNodeChecked event to keep the ID of the checked nodes in a hidden field for later use and to update a checked node counter. 我使用OnClientNodeChecked事件将被检查节点的ID保留在隐藏字段中,以供以后使用并更新被检查节点计数器。

This event is fired everytime the user clicks on a checkbox next to a node. 每当用户单击节点旁边的复选框时,都会触发此事件。 Now, if the user shift + click on a checkbox, then all the checkable child node should be checked/unchecked. 现在,如果用户按Shift +单击复选框,则所有可检查的子节点都应选中/取消选中。

Here is the treeview control: 这是treeview控件:

<telerik:RadTreeView RenderMode="Lightweight" runat="Server" ID="treeAccounts" EnableDragAndDrop="false" EnableDragAndDropBetweenNodes="false" Skin="Vista" CheckBoxes="True"
                OnClientLoad="initializeSelectedNodes" OnClientNodeChecked="treeNodeChecked">
            </telerik:RadTreeView>

And here is the javascript function: (treeNodeChecked is called in the OnClientNodeChecked) 这是JavaScript函数:(在OnClientNodeChecked中调用treeNodeChecked)

var tree;

function treeNodeChecked(sender, eventArgs) {

    tree = $find("<%= treeAccounts.ClientID %>");
    var node = eventArgs.get_node();

    //Here I save the ID of the checked node
    updateSelectedNodes(node);

    if (eventArgs._domEvent.shiftKey || event.shiftKey) {

        var children = node.get_allNodes();
        var checkedState = node.get_checked();

        //If the checked node had children and the shift key was pressed 
        //when the checkbox was clicked then I check/uncheck its child 
        //nodes.
        for(m in children) 
        { 
            var child = children[m];
            child.set_checked(checkedState);

            //Here I save the ID of the child nodes
            updateSelectedNodes(child);
        }
    }
}

This works perfectly in Chrome, Firefox and IE8-, but it doesn´t work in IE9+. 这在Chrome,Firefox和IE8-上完美运行,但在IE9 +中不起作用。 The problem is that in IE9+ both eventArgs._domEvent.shiftKey and event.shiftKey are undefined . 问题在于,在IE9 +中, eventArgs._domEvent.shiftKeyevent.shiftKey未定义

I also tried checking for event.keyCode or event.which but since the event is NOT a keypress or keydown , they are undefined as well. 我也试过检查event.keyCodeevent.which但由于该事件是不是一个按键的keydown,他们是不确定的为好。

Any ideas on how can I make this work in IE9+? 关于如何在IE9 +中进行这项工作的任何想法? Thanks in advance. 提前致谢。

After digging everywhere, I found a way around. 到处挖掘后,我找到了解决方法。

I added this code: 我添加了以下代码:

var shiftKeyPressed;

document.addEventListener("keydown", keyDownEvent, false);

function keyDownEvent(e) {
    var keyCode = e.keyCode;
    if(keyCode==16) {
        shiftKeyPressed = true;
    } 
}

document.addEventListener("keyup", keyUpEvent, false);

function keyUpEvent(e) {
    var keyCode = e.keyCode;
    if(keyCode==16) {
        shiftKeyPressed = false;
    } 
}

And then when I check if the shift key is pressed I added the new variable: 然后,当我检查是否按下了Shift键时,我添加了新变量:

if (eventArgs._domEvent.shiftKey || event.shiftKey || shiftKeyPressed){...}

Now it's working in every browser. 现在,它可以在每种浏览器中使用。

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

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