I have a relation (group_to_snip_snippets) that looks at a global variable (globals.selectedGroupID) and should pull all the records from a table that has an id (snip_group_id) equal to the value of the global variable. I am then populating a DBTreeView with the results. I am having two issues though.
The first issue is that if the global variables value does not have any related records in the table, the tree is being populated with all the records from the table.
The second issue is that if the global variables value does have a match in the table, for each match a tree node is created with child nodes as far deep as I can click of the same name.
Here’s the code I’m using. I outputted the value of the global var and is it being set correctly when the function is called.
function populateTree(_id) {
globals.selectedGroupID=_id;
//Init Navigation Tree
var _jsTree=elements.dbTree_snippets;
_jsTree.removeAllRoots();
_jsTree.refresh();
//Setup tree bindings
var _binding = _jsTree.createBinding(controller.getDataSource());
_binding.setNRelationName('group_to_snip_snippets');
_binding.setTextDataprovider('snip_name');
_binding.setMethodToCallOnClick(globals.onSnipNodeClick, 'snip_id');
//Populate the tree
var _fs=controller.find();
controller.search(true,true);
_jsTree.addRoots(foundset);
}
CFDaddy:
I have a relation (group_to_snip_snippets) that looks at a global variable (globals.selectedGroupID) and should pull all the records from a table that has an id (snip_group_id) equal to the value of the global variable. I am then populating a DBTreeView with the results.
are you saying, you expect the tree to be populated just with the records as a result from your relation?
That case, your code won’t work.
Just for the correct understanding:
_jsTree.addRoots(foundset);
The foundset used in the above line is supposed to contain records which you want to have at first level.
The relation in the above line is used to display childs belonging to the root foundset.
CFDaddy:
The second issue is that if the global variables value does have a match in the table, for each match a tree node is created with child nodes as far deep as I can click of the same name.
Looks like you’ve created a relation which always returns a result…
I’d say you will need at least some search criteria in the ‘populate the tree’ part of your method.
Thanks Marc on both accounts. I was able to resolve both issue by not using a relation that was based on a global variable, but rather just two tables and then adding the search criteria you mentioned. Very much appreciated!