Getting new item reference

5 posts, 0 answers
  1. Simon
    Simon avatar
    159 posts
    Member since:
    Sep 2010

    Posted 23 May 2012 Link to this post

    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








  2. Kamen Bundev
    Admin
    Kamen Bundev avatar
    1532 posts

    Posted 28 May 2012 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Rob
    Rob avatar
    4 posts
    Member since:
    Aug 2012

    Posted 10 Aug 2012 Link to this post

    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.
  5. Simon
    Simon avatar
    159 posts
    Member since:
    Sep 2010

    Posted 05 Jan 2015 Link to this post

    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.
  6. Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 08 Jan 2015 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready