jQWidgets Forums
jQuery UI Widgets › Forums › Plugins › Data Adapter › How to access properties of items in menus defined via data adapter
Tagged: JavaScript Menu, jQuery Menu, jqwidgets menu, Menu, Menu JSON DataAdapter Customer Attributes
This topic contains 5 replies, has 3 voices, and was last updated by loungefurniture 3 years, 9 months ago.
-
Author
-
November 7, 2017 at 8:25 pm How to access properties of items in menus defined via data adapter #97160
Hello Team,
I try to define a jqxMenu via JSON DataAdapter. In the clickhandler I try to access the customer data but I don’t know how. If I try to find them in debug mode my attributes don’t show up.
function createMenuFromJson( data) { var source = { datatype: "json", datafields: [ { name: 'id' }, { name: 'label', type: 'string' }, { name: 'parent' }, { name: 'action', type: 'string' } ], id: 'id', localdata: data }; var dataAdapter = new $.jqx.dataAdapter(source); dataAdapter.dataBind(); var records = dataAdapter.getRecordsHierarchy('id', 'parent', 'items', ['label', 'action']); $('#navigation').jqxMenu({ source: records, mode: 'vertical'}); $("#navigation").on('itemclick', function (event) { alert(event.args.data); }); }
Can you please give me a hint how I can access my data?
Kind Regards
Stephan
November 9, 2017 at 7:37 am How to access properties of items in menus defined via data adapter #97182Hello Stephan,
Please, take a look at this demo:
https://www.jqwidgets.com/jquery-widgets-demo/demos/jqxmenu/menubindingtojson.htm?light
If this does not help you please, clarify it.Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comNovember 9, 2017 at 11:04 am How to access properties of items in menus defined via data adapter #97200Hi Hristo,
this is the demo my code based on. The important lines are:
$("#jqxWidget").on('itemclick', function (event) { $("#eventLog").text("Id: " + event.args.id + ", Text: " + $(event.args).text()); });
There the demo reacts onb a click on an item and executes some JS. In this JS the id and the text is retrieved by event.args.id or $(event.args).text(). Those fields are given in the data source. But how can I get the contents of my field action or how would you get the information of subMenuWidth in the demo?
Best Regards
Stephan
November 9, 2017 at 11:24 am How to access properties of items in menus defined via data adapter #97202Hi Hristo,
I forgot to mention that I tried to access my data in both ways once with event.args.action and once with $(event.args).action(). The result was “undefined” in the first and an error (action is not a function) in the second attempt.
Best Regards
Stephan
November 10, 2017 at 11:33 am How to access properties of items in menus defined via data adapter #97239Hello Stephan,
You should create a custom function that could get data information from your initial records by its ID.
Best Regards,
Hristo HristovjQWidgets team
http://www.jqwidgets.comgreat
-
AuthorPosts
You must be logged in to reply to this topic.