jQWidgets Forums
jQuery UI Widgets › Forums › Navigation › Tree › How to get parent ID? What is the correct approach?
This topic contains 2 replies, has 1 voice, and was last updated by mdmings517 10 years, 4 months ago.
-
Author
-
The code below works fine except I can’t figure out how to get the parentID of a node. I even tried assigning the parentID to the value field and that just produces 0 as a result. What is the correct approach?
function createTree($ID) {
if ($ID == undefined){
$ID = 0;
}
$.ajax({
url: ‘json_directories.php’,
success: function (data) {
var source = {datatype: ‘json’,
datafields: [{name: ‘dir_id’ },{name: ‘parent_id’ },{name: ‘name’}],
id: ‘dir_id’,
localdata: data
};
var dataAdapter = new $.jqx.dataAdapter(source);
dataAdapter.dataBind();
var records = dataAdapter.getRecordsHierarchy(‘dir_id’, ‘parent_id’, ‘items’, [{ name: ‘name’, map: ‘label’},{name: ‘dir_id’, map: ‘id’}]);
$(‘#jqxWidget’).jqxTree({ source: records, width: ‘190px’});
$(‘#jqxWidget’).jqxTree(‘selectItem’,$(‘#’+$ID)[0]);$(‘#jqxTree’).jqxTree({ source: records, width: ‘190px’});
$(“#jqxTree”).jqxTree({ width: 300, height: 220});
$(‘#jqxTree’).jqxTree(‘selectItem’,$(‘#0’)[0]);},
error: function () {
alert(‘The source is unavailable!’);
}//success
});//ajax
}function createTree($ID) { if ($ID == undefined){ $ID = 0; } $.ajax({ url: 'json_directories.php', success: function (data) { var source = {datatype: 'json', datafields: [{name: 'dir_id' },{name: 'parent_id' },{name: 'name'}], id: 'dir_id', localdata: data }; var dataAdapter = new $.jqx.dataAdapter(source); dataAdapter.dataBind(); var records = dataAdapter.getRecordsHierarchy('dir_id', 'parent_id', 'items', [{ name: 'name', map: 'label'},{name: 'dir_id', map: 'id'}]); $('#jqxWidget').jqxTree({ source: records, width: '190px'}); $('#jqxWidget').jqxTree('selectItem',$('#'+$ID)[0]); $('#jqxTree').jqxTree({ source: records, width: '190px'}); $("#jqxTree").jqxTree({ width: 300, height: 220}); $('#jqxTree').jqxTree('selectItem',$('#0')[0]); }, error: function () { alert('The source is unavailable!'); }//success });//ajax }
Found it!
function getParentID(id){ var htmlElement = $('#'+id.toString())[0]; var item = $('#jqxWidget').jqxTree('getItem', htmlElement); var parentId = item.parentId; return parentId; }
-
AuthorPosts
You must be logged in to reply to this topic.