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

Getting new item reference

6 Answers 145 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 23 May 2012, 12:52 PM
In the Kendo Tree View component, when you append a new item, the function will return a reference to the new node.  That way, it's easy to build a node hierarchy:
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

Sort by
0
Kamen Bundev
Telerik team
answered on 28 May 2012, 10:08 AM
Hello Simon,

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
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Rob
Top achievements
Rank 1
answered on 10 Aug 2012, 11:12 PM
Personally (just my opinion) I think that the API should be uniform across the different widgets.

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.
0
Simon
Top achievements
Rank 1
answered on 05 Jan 2015, 04:39 PM
It's always funny when Google bring you back to your own question.

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.
0
Petyo
Telerik team
answered on 08 Jan 2015, 09:16 AM

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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Ody
Top achievements
Rank 1
Veteran
answered on 28 Aug 2020, 08:14 PM
Just adding another rant to say this append functionality sucks.  From a long time Telerik fan, enthusiast and advocate.
0
Neli
Telerik team
answered on 02 Sep 2020, 02:04 PM

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/.

Tags
Menu
Asked by
Simon
Top achievements
Rank 1
Answers by
Kamen Bundev
Telerik team
Rob
Top achievements
Rank 1
Simon
Top achievements
Rank 1
Petyo
Telerik team
Ody
Top achievements
Rank 1
Veteran
Neli
Telerik team
Share this question
or