如何加载负载VB ASP jstree复选框 [英] How to load jstree checkbox on load VB ASP
问题描述
我试图加载jstree使用ASP负载复选框。在code背后需要一个树节点,并填充为jstree使用列表项。在这个过程中,有标识为选中,我在其中添加类属性节点的 jstree-点击应用于列表项。然而,当页面加载时,它不会有任何效果。请让我知道该怎么恰当的方式与相应的复选框来填充这些复选框pre-检查。我在后端以下
保护小组的Page_Load(BYVAL发件人为对象,BYVAL E上System.EventArgs)把手Me.Load
昏暗TNODE作为树节点
昏暗的TreeView作为新的TreeView
昏暗tNodeCollection作为新TreeNodeCollection
tNodeCollection = treeView.Nodes code生成并存储在
一个System.Web.UI.WebControls.TreeView对象
'...
'...
'... repeater.DataSource = tNodeCollection
repeater.DataBind()
结束小组保护小组repeater_ItemDataBound(发送者为对象,E为RepeaterItemEventArgs)
昏暗TNODE作为树节点
李昏暗作为新HtmlGenericControl
昏暗的UL作为新HtmlGenericControl(UL)
TNODE = e.Item.DataItem 如果(TNODE是没有什么)然后
返回
万一 李= e.Item.FindControl(的listItem)
li.ID = tNode.Value
li.InnerHtml = tNode.Text
如果tNode.Checked然后
li.Attributes.Add(相对,真)
万一 如果tNode.ChildNodes.Count> 0,则
li.Controls.Add(UL)
searchChildNodes(tNode.ChildNodes,UL)
万一
结束小组私人小组searchChildNodes(子节点作为TreeNodeCollection,UL作为HtmlGenericControl)
昏暗TNODE作为树节点
对于每个TNODE在子节点
李昏暗作为新HtmlGenericControl(礼)
li.ID = tNode.Value
li.InnerHtml = tNode.Text
ul.Controls.Add(LI)
如果tNode.ChildNodes.Count> 0,则
昏暗unorderedList作为新HtmlGenericControl(UL)
li.Controls.Add(unorderedList)
searchChildNodes(tNode.ChildNodes,unorderedList)
万一
下一个
结束小组
下面是code的ASPX部分。
< DIV ID =myTreeNode>
< ASP:直放站ID =RPTR=服务器的EnableViewState =假OnItemDataBound =repeater_ItemDataBound>
<&HeaderTemplate中GT;
< UL>
< / HeaderTemplate中>
<&ItemTemplate中GT;
<李ID =的listItem=服务器>< /李>
< / ItemTemplate中>
< FooterTemplate>
< / UL>
< / FooterTemplate>
< / ASP:直放站>
< / DIV>
在javascript文件中,jsTree则该属性和$ P $检查,一旦一切都已经加载pselects的复选框。这适当地选择该复选框。如上评论中提及,这避免了只处理CSS而是处理整个节点。
$(#myTreeNode)。绑定(ready.jstree',函数(事件数据){
变量$树= $(本);
$($ tree.jstree()。get_json($树,{
平:真
}))。每个(函数(){
VAR检查= $(本).attr('相对');
VAR节点;
如果(选中==真){
节点= $(#myTreeNode)jstree()select_node(this.id)。
}
});
});
I'm trying to load jstree checkboxes on load using ASP. The code behind takes a tree node and populates a list item for the jstree to use. In this process, there are nodes that are identified as "Checked", in which I add the class attribute jstree-clicked to the list item. However when the page loads, it doesn't have any effect. Please let me know what to the appropriate way to populate these check boxes with the check boxes pre-checked. I have the following in my back end
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim tNode As TreeNode
Dim treeView As New TreeView
Dim tNodeCollection As New TreeNodeCollection
tNodeCollection = treeView.Nodes
' Code to generate and store within
' a System.Web.UI.WebControls.TreeView object
' ...
' ...
' ...
repeater.DataSource = tNodeCollection
repeater.DataBind()
End Sub
Protected Sub repeater_ItemDataBound(sender As Object, e As RepeaterItemEventArgs)
Dim tNode As TreeNode
Dim li As New HtmlGenericControl
Dim ul As New HtmlGenericControl("ul")
tNode = e.Item.DataItem
If (tNode Is Nothing) Then
Return
End If
li = e.Item.FindControl("listItem")
li.ID = tNode.Value
li.InnerHtml = tNode.Text
If tNode.Checked Then
li.Attributes.Add("rel", "true")
End If
If tNode.ChildNodes.Count > 0 Then
li.Controls.Add(ul)
searchChildNodes(tNode.ChildNodes, ul)
End If
End Sub
Private Sub searchChildNodes(childNodes As TreeNodeCollection, ul As HtmlGenericControl)
Dim tNode As TreeNode
For Each tNode In childNodes
Dim li As New HtmlGenericControl("li")
li.ID = tNode.Value
li.InnerHtml = tNode.Text
ul.Controls.Add(li)
If tNode.ChildNodes.Count > 0 Then
Dim unorderedList As New HtmlGenericControl("ul")
li.Controls.Add(unorderedList)
searchChildNodes(tNode.ChildNodes, unorderedList)
End If
Next
End Sub
Below is the aspx portion of the code.
<div id="myTreeNode" >
<asp:Repeater ID="rptr" runat="server" EnableViewState="False" OnItemDataBound="repeater_ItemDataBound" >
<headerTemplate>
<ul>
</headerTemplate>
<ItemTemplate>
<li id="listItem" runat="server"></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</div>
In the javascript file, the jsTree then checks for the attribute and preselects the check box once everything has been loaded. This appropriately selects the check box. As mentioned in the comment above, this avoids only handling the CSS but rather handles the entire node.
$("#myTreeNode").bind('ready.jstree', function (event, data) {
var $tree = $(this);
$($tree.jstree().get_json($tree, {
flat: true
})).each(function () {
var checked = $(this).attr('rel');
var node;
if( checked == "true"){
node = $("#myTreeNode").jstree().select_node(this.id);
}
});
});
这篇关于如何加载负载VB ASP jstree复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!