RadControls for ASP.NET AJAX
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.
Note |
|---|
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.
|
Name | Parameters | Return Type | Description |
|---|
add | RadMenuItem | none | Adds a child item to the collection. |
CopyJavaScript
var menu = $find("<%= RadMenu1.ClientID %>");
menu.trackChanges();
var childItem = new Telerik.Web.UI.RadMenuItem();
childItem.set_text("New");
menu.get_items().add(childItem);
menu.commitChanges();
insert | int, RadMenuItem | none | Inserts the item into the collection at the position defined by the first (index) parameter. |
CopyJavaScript
var menu = $find("<%= RadMenu1.ClientID %>");
menu.trackChanges();
var childItem = new Telerik.Web.UI.RadMenuItem();
childItem.set_text("New");
menu.get_items().insert(0, childItem);
menu.commitChanges();
remove | RadMenuItem | none | Removes the specified item from the collection. |
CopyJavaScript
var menu = $find("<%= RadMenu1.ClientID %>");
var menuItem = menu.get_items().getItem(0);
menu.trackChanges();
menu.get_items().remove(menuItem);
menu.commitChanges();
clear | none | none | Clears the Items collection of all the child items it contains. |
CopyJavaScript
var menu = $find("<%= RadMenu1.ClientID %>");
menu.trackChanges();
menu.get_items().getItem(0).get_items().clear();
menu.commitChanges();
getItem | int | RadMenuItem | Returns the item from the collection that resides at the specified index. |
CopyJavaScript
var menu = $find("<%= RadMenu1.ClientID %>");
var rootItem1 = menu.get_items().getItem(0);
indexOf | RadMenuItem | int | Returns the index of an item. |
CopyJavaScript
var menu = $find("<%= RadMenu1.ClientID %>");
var rootItem2 = menu.get_items().getItem(1);
var index = menu.get_items().indexOf(rootItem2);
removeAt | int | none | Removes the item at the specified index. |
CopyJavaScript
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);
get_count | none | int | Returns the number of the items in the collection. |
CopyJavaScript
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());
}
See Also