This is a migrated thread and some comments may be shown as answers.

Accessing Html Attribute in treeview

1 Answer 570 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Bartley
Top achievements
Rank 1
Bartley asked on 10 Nov 2013, 04:53 PM
Hello I have a treeview where I have added a integer Id as a hmtlattribute.  This is a MVC4 Kendo UI project.

branch.Add().Text("Item " + child).HtmlAttributes(new { data_foo = childs.MyId })

I am trying to access it from a button click event when a node is selected to pass foo to another view.

$("#btn").click(function () {
        var treeview = $("#treeview").data("kendoTreeView");
        var treeSelect = treeview.select();
        var passId = treeSelect.attr("foo");
        window.location = "@Url.Action("Index","Content")" + "?MyIntegerParameter=" + passId;*
});

Here is the element from Chrome

<li class="k-item" data-foo="30" data-uid="7f3430d0-4b01-4b08-b4be-1264d3ff16d3" role="treeitem" aria-selected="true" id="treeview_tv_active">
    <div class="k-top">
        <span class="k-in k-state-selected">This Is The Text</span>
    </div>
</li>

How can I access this from the button click and send it in the Action?

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimiter Madjarov
Telerik team
answered on 11 Nov 2013, 12:55 PM
Hi Bartley,


If I understand you correctly you would like to access the data-foo attribute. If that is the current case, you could use jQuery's data or attr methods.
E.g.
tree.select().attr("data-foo")

tree.select().data("foo")

I hope that this was the information that you were looking for.

Regards,
Dimiter Madjarov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
TreeView
Asked by
Bartley
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or