jQWidgets Forums
jQuery UI Widgets › Forums › Navigation › Menu, Context Menu › jqxMenu not loading with remote json
This topic contains 3 replies, has 2 voices, and was last updated by defyent 1 year, 8 months ago.
-
Author
-
Hello,
When I use localdata with a json based jqxMenu, my menus load fine, however when I transfer this to url based json my menus are blank, no menus display at all. I can see in my server logs that my source.txt is being called, and my json data is valid, but nothing is loading. Any ideas what I’m doing wrong?
You can view my example at https://new.datahangar.co.nz/templates/index.html
Hi,
You can load it this way:
$(document).ready(function () {// var data = [{
// “id”: “1”,
// “text”: “Operations”,
// “parentid”: “-1”,
// “subMenuWidth”: “250px”
// },
// {
// “id”: “2”,
// “parentid”: “1”,
// “text”: “Flight Schedule”
// }
// ]fetch(‘./source.txt’)
.then(res => res.json())
.then(data => {
var menu_source = {
datatype: “json”,
datafields: [
{ name: ‘id’ },
{ name: ‘parentid’ },
{ name: ‘text’ },
{ name: ‘subMenuWidth’ }
],
id: ‘id’,
localdata: data,
};
var menuDataAdapter = new $.jqx.dataAdapter(menu_source);
menuDataAdapter.dataBind();
var menu_records = menuDataAdapter
.getRecordsHierarchy(
‘id’,
‘parentid’,
‘items’,
[{
name: ‘text’,
map: ‘label’
}]
);$(‘#topmenu’).jqxMenu({
source: menu_records,
height: 25,
//width: ‘99.9%’,
//autoOpen: false,
//autoSizeMainItems: true,
//theme: ‘metrodark’,// less than this number will minimize menu
});
})
});I hope this helps!
Best regards,
Svetoslav BorislavovjQWidgets Team
https://www.jqwidgets.com/Thank you for the quick reply, the above solution has a scope error, as menu_source can not be accessed outside of the .then statement. If I define menu_source before the fetch, I get the following error.
ncaught TypeError: Cannot read properties of undefined (reading ‘beforeLoadComplete’)
at new $.jqx.dataAdapter (jqxdata.js:636:21)
at HTMLDocument.<anonymous> (index.html:71:39)
at j (jquery-1.11.1.min.js:2:27244)
at Object.fireWith [as resolveWith] (jquery-1.11.1.min.js:2:28057)
at Function.ready (jquery-1.11.1.min.js:2:29891)
at HTMLDocument.J (jquery-1.11.1.min.js:2:30257)Nevermind, I replicated the code wrong. All working now. Thank you again !
-
AuthorPosts
You must be logged in to reply to this topic.