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

1 Answer 1

0

After trying so many things , I checked their demo and found the hints there (I shouldve done this as the first thing).

It was actually pretty straight forward

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

Thanks,

A

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.