rootNode = myTreeView.append({ text:
"MyRoot"
},
null
);
subNode = myTreeView.append({ text:
"MySubNode"
}, rootNode);
myTreeView.append({ text:
"MyThirdLevelNode1"
}, subNode);
myTreeView.append({ text:
"MyThirdLevelNode2"
}, subNode);
However, I can't find a way to do the same with the Kendo Menu component. So far, the only I've found to create a menu dynamically is adding a specific ID and getting the menu item with this ID.
MyMenu.append(
'<li id="RootMenuItem" class="k-item">MyRootItem</li>'
);
MyMenu.append(
'<li id="MySubItem" class="k-item">SubItem</li>'
, $(
"#RootMenuItem"
));
Is there a way to get the newly created item and reuse it as the parent reference for the menu?
Regards,
Simon
6 Answers, 1 is accepted
You are correct, the Menu widget append() method returns a reference to the menu itself, not to the appended items. However you can directly append items plus their subitems, using the items property, something like this:
menu.append([{
text: "Parent Item",
items: [{
text: "Sub Item 1"
},
{
text: "Sub Item 2"
}]
}]);
Does this help in your specific use case? Meanwhile we'll think of a better way to get the last appended items.
Regards,
Kamen Bundev
the Telerik team

In most cases if you are calling a method where it is valuable to have the new item returned, that should supercede any potential case where you want chaining. Chaining looks nice but it super-unhelpful in these cases.

2 years later, I'm dealing with the same problem again. In the first project, the main menu was more static so I've been able to implement a workaround. This time, I'm trying to generate a dynamic context menu using html tag.
As long as the parent element is the root menu, there's no reference problem. However, when you want to append 2 levels of sub menu using html tag, it would be very useful to get reference to the menu that was created using the append method.
Hello Simon,
thank you for re-opening this thread. We haven't changed the append method signature, mostly due to backwards compatibility and compliance with the jQuery append method.
Regards,Petyo
Telerik

Hello Ody,
Thank you for the feedback. I am sorry to hear that you are not satisfied with the provided Menu functionality. Could you please send more information about the issue you have problems with? In case you have any ideas or recommendations for improving our widgets or documentation you could always log an issue in our official Feedback Portal. Thus, we could track the interest of the community to the logged request.
Regards,
Neli
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.