RadMenuItemCollection Object
The RadMenuItemCollection object is returned by the get_items method of the RadMenu object or the RadMenuItem object. The following table lists the most important methods.
Changes to the item collection made using these methods do not persist after a postback unless surrounded by a call to the trackChanges method of the menu object and the commitChanges method of the menu object.
In Mobile render mode, client-side RadMenu items are of type
Telerik.Web.UI.MobileMenuItem
while in the other render modes the items are of typeTelerik.Web.UI.RadMenuItem
.
Name | Parameters | Return Type | Description |
---|---|---|---|
add | RadMenuItem | none | Adds a child item to the collection. See Example 1. |
insert | int, RadMenuItem | none | Inserts the item into the collection at the position defined by the first (index) parameter. See Example 2. |
remove | RadMenuItem | none | Removes the specified item from the collection. See Example 3. |
clear | none | none | Clears the Items collection of all the child items it contains. See Example 4. |
getItem | int | RadMenuItem | Returns the item from the collection that resides at the specified index. See Example 5. |
indexOf | RadMenuItem | int | Returns the index of an item. See Example 6. |
removeAt | int | none | Removes the item at the specified index. See Example 7. |
get_count | none | int | Returns the number of the items in the collection. See Example 8. |
var menu = $find("<%= RadMenu1.ClientID %>");
menu.trackChanges();
var menuItemClass = Telerik.Web.UI.RadMenuItem || Telerik.Web.UI.MobileMenuItem;
var childItem = new menuItemClass();
childItem.set_text("New");
menu.get_items().add(childItem);
menu.commitChanges();
var menu = $find("<%= RadMenu1.ClientID %>");
menu.trackChanges();
var menuItemClass = Telerik.Web.UI.RadMenuItem || Telerik.Web.UI.MobileMenuItem;
var childItem = new menuItemClass();
childItem.set_text("New");
menu.get_items().insert(0, childItem);
menu.commitChanges();
var menu = $find("<%= RadMenu1.ClientID %>");
var menuItem = menu.get_items().getItem(0);
menu.trackChanges();
menu.get_items().remove(menuItem);
menu.commitChanges();
var menu = $find("<%= RadMenu1.ClientID %>");
menu.trackChanges();
menu.get_items().getItem(0).get_items().clear();
menu.commitChanges();
var menu = $find("<%= RadMenu1.ClientID %>");
var rootItem1 = menu.get_items().getItem(0);
var menu = $find("<%= RadMenu1.ClientID %>");
var rootItem2 = menu.get_items().getItem(1);
var index = menu.get_items().indexOf(rootItem2);
var menu = $find("<%= RadMenu1.ClientID %>");
var item = menu.findItemByText("victim");
var items = item.get_parent().get_items();
var index = items.indexOf(item);
items.removeAt(index);
var menu = $find("<%= RadMenu1.ClientID %>");
var items = menu.get_items();
for (var i = 0; i < items.get_count(); i++) {
alert(items.getItem(i).get_text());
}