I need to know how to build a multi-level menu from an XML data source. Right now the child elements are appearing in the main level.
My JavaScript:
My XML Data Source:
My JavaScript:
var template_navigation_menu = kendo.template('<
li
><
a
href
=
"#=url#"
target
=
"#=target#"
title
=
"#=title#"
>#=text#</
a
></
li
>');
var navigation_menu = $("#navigation_menu").kendoMenu();
$(document).ready(function () {
function navigation_menu_render()
{
$("#navigation_menu").html(kendo.render(template_navigation_menu, this.view()));
}
var datasource_navigation_menu = new kendo.data.DataSource(
{
transport:
{
read: "xml/navigation" + get_culture_path_modifier() + ".xml"
},
schema:
{
type: "xml",
data: "/navigation/menu/item",
model:
{
fields:
{
item_id: "item_id/text()",
parent_id: "parent_id/text()",
text: "text/text()",
url: "url/text()",
target: "target/text()",
title: "title/text()",
google_sitemap_priority: "google_sitemap_priority/text()",
google_sitemap_frequency: "google_sitemap_frequency/text()",
main_inclusion: "main_inclusion/text()",
footer_inclusion: "footer_inclusion/text()"
}
}
},
change: navigation_menu_render
});
datasource_navigation_menu.filter({ field: "main_inclusion", operator: "eq", value: "true" });
datasource_navigation_menu.read();
});
My XML Data Source:
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
navigation
>
<
menu
>
<
item
>
<
item_id
>1</
item_id
>
<
parent_id
>0</
parent_id
>
<
text
>Home</
text
>
<
url
>/</
url
>
<
target
>_top</
target
>
<
title
>Click here to return to the Home Page.</
title
>
<
google_sitemap_priority
>1.0</
google_sitemap_priority
>
<
google_sitemap_frequency
>daily</
google_sitemap_frequency
>
<
main_inclusion
>true</
main_inclusion
>
<
footer_inclusion
>true</
footer_inclusion
>
</
item
>
</
menu
>
<
menu
>
<
item
>
<
item_id
>2</
item_id
>
<
parent_id
>0</
parent_id
>
<
text
>Item 1</
text
>
<
url
>/item.html</
url
>
<
target
>_top</
target
>
<
title
>Click here to view item 1.</
title
>
<
google_sitemap_priority
>0.8</
google_sitemap_priority
>
<
google_sitemap_frequency
>daily</
google_sitemap_frequency
>
<
main_inclusion
>true</
main_inclusion
>
<
footer_inclusion
>true</
footer_inclusion
>
</
item
>
</
menu
>
<
menu
>
<
item
>
<
item_id
>3</
item_id
>
<
parent_id
>0</
parent_id
>
<
text
>Item 2</
text
>
<
url
>/item.html</
url
>
<
target
>_top</
target
>
<
title
>Click here to view item 2.</
title
>
<
google_sitemap_priority
>0.5</
google_sitemap_priority
>
<
google_sitemap_frequency
>daily</
google_sitemap_frequency
>
<
main_inclusion
>true</
main_inclusion
>
<
footer_inclusion
>true</
footer_inclusion
>
</
item
>
</
menu
>
<
menu
>
<
item
>
<
item_id
>4</
item_id
>
<
parent_id
>0</
parent_id
>
<
text
>Item 3</
text
>
<
url
>/item.html</
url
>
<
target
>_top</
target
>
<
title
>Click here to view item 3.</
title
>
<
google_sitemap_priority
>0.8</
google_sitemap_priority
>
<
google_sitemap_frequency
>weekly</
google_sitemap_frequency
>
<
main_inclusion
>true</
main_inclusion
>
<
footer_inclusion
>true</
footer_inclusion
>
</
item
>
</
menu
>
<
menu
>
<
item
>
<
item_id
>5</
item_id
>
<
parent_id
>0</
parent_id
>
<
text
>Footer-Only Item 1</
text
>
<
url
>/item.html</
url
>
<
target
>_blank</
target
>
<
title
>Click here to view item.</
title
>
<
google_sitemap_priority
>0.3</
google_sitemap_priority
>
<
google_sitemap_frequency
>monthly</
google_sitemap_frequency
>
<
main_inclusion
>false</
main_inclusion
>
<
footer_inclusion
>true</
footer_inclusion
>
</
item
>
</
menu
>
<
menu
>
<
item
>
<
item_id
>6</
item_id
>
<
parent_id
>0</
parent_id
>
<
text
>Footer-Only Item 2</
text
>
<
url
>/item.html</
url
>
<
target
>_blank</
target
>
<
title
>Click here to view item.</
title
>
<
google_sitemap_priority
>0.3</
google_sitemap_priority
>
<
google_sitemap_frequency
>monthly</
google_sitemap_frequency
>
<
main_inclusion
>false</
main_inclusion
>
<
footer_inclusion
>true</
footer_inclusion
>
</
item
>
</
menu
>
<
menu
>
<
item
>
<
item_id
>7</
item_id
>
<
parent_id
>0</
parent_id
>
<
text
>Item 4</
text
>
<
url
>/item.html</
url
>
<
target
>_top</
target
>
<
title
>Click here to view item.</
title
>
<
google_sitemap_priority
>0.3</
google_sitemap_priority
>
<
google_sitemap_frequency
>monthly</
google_sitemap_frequency
>
<
main_inclusion
>true</
main_inclusion
>
<
footer_inclusion
>true</
footer_inclusion
>
</
item
>
</
menu
>
<
menu
>
<
item
>
<
item_id
>8</
item_id
>
<
parent_id
>7</
parent_id
>
<
text
>Item 4 - Sub Item 1</
text
>
<
url
>/subitem.html</
url
>
<
target
>_top</
target
>
<
title
>Click here to view sub item.</
title
>
<
google_sitemap_priority
>0.3</
google_sitemap_priority
>
<
google_sitemap_frequency
>monthly</
google_sitemap_frequency
>
<
main_inclusion
>true</
main_inclusion
>
<
footer_inclusion
>true</
footer_inclusion
>
</
item
>
</
menu
>
</
navigation
>