0

Following is how I populate my jqTreeView.

View

    @Html.Trirand().JQTreeView(
    new JQTreeView
    {
        DataUrl = Url.Action("RenderTree"),
        Height = Unit.Pixel(500),
        Width = Unit.Pixel(150),
        HoverOnMouseOver = false,
        MultipleSelect = false,
        ClientSideEvents = new TreeViewClientSideEvents()
        {
            Select="spawnTabAction"
        }
    }, 
    "treeview"
    )

   <script>
   function spawnTabAction(args, event) {
       alert(args);
   }
   </script>

Controller

    public JsonResult RenderTree()
    {
        var tree = new JQTreeView();

        List<JQTreeNode> nodes = new List<JQTreeNode>();

        nodes.Add(new LeafNode { Text = "Products", Value="Product/Product/Index" });
        FolderNode fNode = new FolderNode { Text = "Customers" };
        fNode.Nodes.Add(new LeafNode() { Text = "Today's Customers", Value = "Customer/Customer/Today" });
        nodes.Add(fNode);
        nodes.Add(new LeafNode { Text = "Suppliers", Value = "Supplier/Supplier/Index" });
        nodes.Add(new LeafNode { Text = "Employees", Value = "Employee/Employee/Index" });
        nodes.Add(new LeafNode { Text = "Orders", Value = "Order/Order/Index" });

        return tree.DataBind(nodes);
    }

What I want to do is spawn a tab based on the Value of the selected node. I tried a lot but couldn't get hold of the selected node's value.

Later I checked the DOM of rendered page and found that the value is nowhere added to the node but magically when I select the node the value appears in a hidden control by the name treeview_selectedState (treeview being the id of the control). I even traced all ajax calls but couldn't find anything.

Questions: 1) Where does it keep the Values of tree nodes? 2) How do I get the Selected Node's value in select event?

I even tried to get the treeview_selectedState control's value in select event but it returned []. Then I added a button the view and hooked that onto a js function and found the value there. It makes me think that the value is not available in select event, am I right in thinking that?

I don't think getting selected node's value should be a this big deal? Am I missing something very obvious?

Thanks, A

4

1 回答 1

0

在尝试了这么多事情之后,我检查了他们的演示并在那里找到了提示(我应该首先这样做)。

这实际上很简单

    function spawnTabAction(args, event) {
        alert($("#treeview").getTreeViewInstance().getNodeOptions(args).value);
    }

谢谢,

一个

于 2013-05-16T04:27:35.820 回答