简体   繁体   English

在RadTreeView的Telerik RadTreeNode的节点模板中找到单选按钮控件

[英]Find a radio button control in Node Template of Telerik RadTreeNode of RadTreeView

I am trying to find a radio button control in the node template of rad tree view. 我试图在rad树视图的节点模板中找到一个单选按钮控件。 In JavaScript, i can get all nodes but not this radio control. 在JavaScript中,我可以获取所有节点,但不能获取此无线电控件。

My requirement is a tree view with check boxes and 2 radio buttons for item options. 我的要求是带有复选框和2个单选按钮的项目选项的树状视图。

I am using following code in asp.net 我在asp.net中使用以下代码

<div>
                <telerik:RadTreeView ID="Tree" runat="server" ShowLineImages="True" CheckBoxes="true"> 
                <Nodes> 
                   <telerik:RadTreeNode runat="server" Text="Product" Expanded="false">
                    <Nodes>
                        <telerik:RadTreeNode Text="Item 1">
                            <Nodes>
                                <telerik:RadTreeNode runat="server" Text="Type" Checkable="false">  
                                <NodeTemplate> 
                                    <div> 
                                        <asp:RadioButton runat="server" ID="RB1" Text="Option 1" GroupName="StandardTags" /><br /> 
                                        <asp:RadioButton runat="server" ID="RB2" Text="Option 2" GroupName="StandardTags" />
                                    </div> 
                                </NodeTemplate> 
                                </telerik:RadTreeNode>
                            </Nodes>
                        </telerik:RadTreeNode>

                        <telerik:RadTreeNode Text="Item 2">
                            <Nodes>
                                <telerik:RadTreeNode runat="server" Text="Type" Checkable="false">  
                                <NodeTemplate> 
                                <div> 
                                    <asp:RadioButton runat="server" ID="RB3" Text="Option 1" GroupName="StandardTags" /><br /> 
                                    <asp:RadioButton runat="server" ID="RB4" Text="Option 2" GroupName="StandardTags" />
                                </div> 
                                </NodeTemplate> 
                                </telerik:RadTreeNode>
                            </Nodes>
                        </telerik:RadTreeNode>
                    </Nodes>
                    </telerik:RadTreeNode>
                </Nodes> 
                </telerik:RadTreeView>        
                <telerik:RadButton runat="server" OnClientClicked="findControl" Text="Find Control" AutoPostBack="false"></telerik:RadButton>

           </div>

I am trying to get nodes in JavaScript like this 我试图像这样在JavaScript中获取节点

function findControl() {
              var tree = $find('<%=Tree.ClientID%>');
              var element = tree.findNodeByText("Item 1").get_text();

              alert('You have selected ' + element);
          }

But I cannot find any option to select radio buttons in 'Item 1'. 但是我找不到在“项目1”中选择单选按钮的任何选项。

I need to get node and selected value of radio button. 我需要获取节点和单选按钮的选定值。

If there is any other to achieve this functionality, please suggest. 如果还有其他方法可以实现此功能,请提出建议。

Many Thanks 非常感谢

You have to follow the same control heirarchy when trying to find a control in javascript. 尝试在javascript中查找控件时,必须遵循相同的控件层次结构。

var tree = $find("<%= Tree.ClientID %>");

var cDiv = tree.findNodeByText("Item 1").get_nodes().getNode(0).get_contentElement();

var radioBtn = $(cDiv).find("input:radio");

radioBtn.each(function (index, element) {

        alert(element.value + ' = ' + element.checked);

});

Notice that after findNodeByText("Item 1") , i am getting all child nodes, and then take the first node (The node containing the text "Type") and then the html using get_contentElement(); 请注意,在findNodeByText(“ Item 1”)之后 ,我将获取所有子节点,然后获取第一个节点(包含文本“ Type”的节点),然后使用get_contentElement();

After that , you can use regular jquery to find the radio buttons and manipulate them as you wish. 之后,您可以使用常规jquery查找单选按钮并根据需要进行操作。

Telerik client side documentation Telerik客户端文档

RadTreeNode RadTreeNodeCollection RadTreeNode RadTreeNodeCollection

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

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