I am using Kendo menu in my project. I want to retrieve id value when I click on the selected item. I used onSelect event and I am able to retrieve the selected item Text. How can I retrieve the id value?
You can use HTML5 data atrributes to accomplish this.
HTML
<div id="example" class="k-content">
<ul id="menu">
<li>
First Item
<ul>
<li data-id="12345">Sub Item 1 with ID</li>
<li>Sub Item 2</li>
<li>Sub Item 3</li>
<li>Sub Item 4</li>
</ul>
</li>
<li>
Second Item
<ul>
<li>Sub Item 1</li>
<li>Sub Item 2</li>
<li>Sub Item 3</li>
<li>Sub Item 4</li>
</ul>
</li>
<li>
Third Item
<ul>
<li>Sub Item 1</li>
<li>Sub Item 2</li>
<li>Sub Item 3</li>
<li>Sub Item 4</li>
</ul>
</li>
<li>
Fourth Item
<ul>
<li>Sub Item 1</li>
<li>Sub Item 2</li>
<li>Sub Item 3</li>
<li>Sub Item 4</li>
</ul>
</li>
<li>
Fifth Item
<ul>
<li>Sub Item 1</li>
<li>Sub Item 2</li>
<li>Sub Item 3</li>
<li>Sub Item 4</li>
</ul>
</li>
</ul>
</div>
And the Javascript:
<script>
$(document).ready(function() {
function onSelect(e) {
var id = $(e.item).attr('data-id');
}
$("#menu").kendoMenu({
select: onSelect
});
});
</script>
You can set an ID in the UL/LI structure from which you initialize it (check the Robotsushi's answer). However if you want to initialize the menu dynamically you can use something like this - http://jsfiddle.net/MMRCf/8/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With