jQWidgets Forums
jQuery UI Widgets › Forums › Navigation › Menu, Context Menu › Cannot access ID or parent ID
This topic contains 3 replies, has 3 voices, and was last updated by igikloppers 10 years, 2 months ago.
-
Author
-
Hi,
I’m using Json data to populate the Menu. But I cant access the ID on click. it gives a generic id(like menuItem9903883167853252000). And how do I access other information, like the url?
<head runat=”server”>
<title></title>
<link rel=”stylesheet” href=”../../core/thirdparty/jqwidgets/styles/jqx.base.css” type=”text/css” />
<script type=”text/javascript” src=”../../core/thirdparty/jQuery/js/jquery.min.js”></script>
<script type=”text/javascript” src=”../../core/thirdparty/jqwidgets/jqxcore.js”></script>
<script type=”text/javascript” src=”../../core/thirdparty/jqwidgets/jqxdata.js”></script>
<script type=”text/javascript” src=”../../core/thirdparty/jqwidgets/jqxbuttons.js”></script>
<script type=”text/javascript” src=”../../core/thirdparty/jqwidgets/jqxscrollbar.js”></script>
<script type=”text/javascript” src=”../../core/thirdparty/jqwidgets/jqxmenu.js”></script><script type=”text/javascript”>
$(document).ready(function () {
var postData = ‘{“CurrentPersonID”:”‘ + “A690CEE9-86DE-4700-BC08-D3F130643AC5″ + ‘”}’;
//alert(postData);
var ListPageUrl = ‘/WholeFoodsMarket/applications/Setup/Menu.aspx/List’;
$.ajax({
type: “POST”,
url: ListPageUrl,
contentType: “application/json; charset=utf-8”,
data: postData,
dataType: “json”,
cache: false,
success: function (data) {
var source =
{
datatype: “json”,
datafields: [
{ name: ‘ID’ },
{ name: ‘parentID’ },
{ name: ‘text’ },
{ name: ‘value’ }],
id: ‘ID’,
localdata: data.d
};
// create data adapter.0
var dataAdapter = new $.jqx.dataAdapter(source);
// perform Data Binding.
dataAdapter.dataBind();
// get the menu items. The first parameter is the item’s id. The second parameter is the parent item’s id. The ‘items’ parameter represents
// the sub items collection name. Each jqxTree item has a ‘label’ property, but in the JSON data, we have a ‘text’ field. The last parameter
// specifies the mapping between the ‘text’ and ‘label’ fields.
var records = dataAdapter.getRecordsHierarchy(‘ID’, ‘parentID’, ‘items’, [{ name: ‘text’, map: ‘label’}]);
$(‘#jqxWidget’).jqxMenu({ source: records, height: 30, theme: ‘energyblue’});
$(“#jqxWidget”).on(‘itemclick’, function (event) {
$(“#eventLog”).text(“Id: ” + event.args.id + “, Text: ” + $(event.target).val());
//alert(event.args.parentID);
});
},
error: function (msg) {
// $(‘#ErrorMessage’).val(msg);
}
});});
</script>
</head>
<body>
<form id=”form1″ runat=”server”><div>
</div>
<div id=’jqxWidget’>
</div>
<div style=”margin-top: 50px; font-size: 13px; font-family: Verdana;” id=”eventLog”></div>
</form>
</body>
</html>Thank you!
PriyamHello Priyam,
The issue comes from the fact that you have “ID” and “parentID” and not “id” and “parentid”. You would have to map your properties, as you did with “text” (which is mapped to “label”).
And could you clarify what url you need to access?
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hi Dimitar,
Could you perhaps explain how to map the “text” as “label”, as well as “ID” as “id” in the above scenario. In other words, is it possible to map more than one property? Also then, after the click event, how do I access those properties ?
Regards,
IgiHi,
I found the solution in part of the XML example, thanks –
var records = dataAdapter.getRecordsHierarchy(‘ID’, ‘parentID’, ‘items’, [{ name: ‘text’, map: ‘label’}, { name: ‘id’, map: ‘ID’)]);Regards,
Igi -
AuthorPosts
You must be logged in to reply to this topic.