如何以编程方式添加Kendo菜单项?

时间:2013-01-29 14:26:38

标签: kendo-ui

如何以编程方式将菜单项添加到Kendo菜单?

var menu = $("#menu").data("kendoMenu");
var item1 = menu.append({text: "Option 1"});
var item2 = menu.append({text: "Option 2"}, item1);

这会将项目彼此相邻添加,但我希望选项2成为选项1的子项目。

我该怎么做?

由于

1 个答案:

答案 0 :(得分:0)

我跳这个例子可以帮到你:

|Menu 1 | Menu 2 |

CODE

var menu = $("#menu1").data("kendoMenu");

menu.append({text: "OneMoreMenu",cssClass:"OneMoreMenu"});

结果:

|Menu 1 | Menu 2 | **OneMoreMenu**

CODE:

menu.append({text: "SubMenu1", cssClass:"SubMenu1"}, $('.OneMoreMenu'));
menu.append({text: "SubMenu2",cssClass:"SubMenu2"}, $('.OneMoreMenu'));

结果:

|Menu 1 | Menu 2 | **OneMoreMenu**
___________________ |SubMenu1
___________________ |SubMenu2

代码:

menu.append({text: "SubMenu2_1",cssClass:"SubMenu2_1"}, $('.SubMenu2'));
menu.append({text: "SubMenu2_2",cssClass:"SubMenu2_2"}, $('.SubMenu2'));

结果:

|Menu 1 | Menu 2 | **OneMoreMenu**
___________________ |SubMenu1
___________________ |SubMenu2___|SubMenu2_1
________________________________|SubMenu2_2