how to load the kendoMenu dynamically using dataSo

2019-08-17 18:34发布

问题:

I want to use kendoMenu. I want to load the menu with parent and child fields dynamically. Can anyone tell me how to load the kendoMenu dynamically using json/datasource?

回答1:

Kendo Menu doesn't currently support the hierarchical data source. You can initialize it dynamically using a JSON object, like this:
http://docs.kendoui.com/getting-started/web/menu/overview#initialize-the-menu-using-json-data-object



回答2:

This may be redundant to Bundyo's answer, but who doesn't like examples? :) This worked for me:

$.get("remoteMenu.php", function(data) {
    $("#menu").kendoMenu({
        dataSource: data
    });
});

Whereby, the "remoteMenu.php" returns a JSON object like:

[{"text":"Baseball","url":"requests","imageUrl":"http:\/\/demos.kendoui.com\/content\/shared\/icons\/sports\/baseball.png"},{"text":"Golf","url":"agencies","imageUrl":"http:\/\/demos.kendoui.com\/content\/shared\/icons\/sports\/golf.png"}]