jQuery UI Widgets Forums Navigation Tree Store ID values for tree items

Tagged: ,

This topic contains 1 reply, has 2 voices, and was last updated by  Peter Stoev 12 years, 4 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Store ID values for tree items #4120

    timaios
    Member

    Hi,

    I need to associate the items of a tree with some unique ID, so that I can identify the correct item in the select event handler, even if the tree contains items with the same label. I’ve tried to do this by creating a source object [ { label: ‘Item 1’, id: 1, items: [] }, { label: ‘Item 2’, id: 2, items: [] } ], but this (obviously) didn’t work. Adding a custom property (such as my_id) doesn’t work either, reading it back results in an “undefined” value.

    Is it possible to store a unique ID (I’m using version 2.1 of jqWidgets) or do I need to manipulate the HTML DOM to create some li elements with custom id attributes?

    Store ID values for tree items #4124

    Peter Stoev
    Keymaster

    Hi timaios,

    The ‘id’ that you set in the source object is set to the DOM element that represents the tree item.

    For example:

    – Create a tree.

    var source = [
    { id: 1, icon: "../../images/mailIcon.png", label: "Mail", expanded: true, items: [
    { id: 2, icon: "../../images/calendarIcon.png", label: "Calendar" },
    { id: 3, icon: "../../images/contactsIcon.png", label: "Contacts", selected: true }
    ]
    },
    { icon: "../../images/folder.png", label: "Inbox", expanded: true, items: [
    { icon: "../../images/folder.png", label: "Admin" },
    { icon: "../../images/folder.png", label: "Corporate" },
    { icon: "../../images/folder.png", label: "Finance" },
    { icon: "../../images/folder.png", label: "Other" },
    ]
    },
    { icon: "../../images/recycle.png", label: "Deleted Items" },
    { icon: "../../images/notesIcon.png", label: "Notes" },
    { iconsize: 14, icon: "../../images/settings.png", label: "Settings" },
    { icon: "../../images/favorites.png", label: "Favorites" },
    ];
    // create jqxTree
    $('#jqxTree').jqxTree({ source: source, width: '250px', theme: ''});

    – get the element with id = 1

    var element = $('#jqxTree').find('#1');

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.