Topic: Combining setChecked with json loading
I have been trying to understand/fix this now for three days ![]()
I have a page rather like the demo 'Tree simple checkboxes' so that as each node is opened up an AJAX call is made to retrieve the next section of the tree.
My understanding is that if I call setChecked, which recursively navigates the tree looking for the node to check, it will not be able to check a node that has not yet been loaded. (Seems reasonable).
So if when I display a page where there is a checkbox tree with some boxes I want to check (even if they are not yet opened up) I have to load the whole tree? (Or at least those portions of the tree that need to be checked).
So, what I want is code that allows me to preload the whole tree, then I can make a call to setChecked.
However, it seems that I need to make a call to tree.loadOptions and this over-writes any checked values, and I can't get my page to open nodes if I leave it out!
function setupTree(data,tContainer,tFormField,tTreeData,tAjaxUri) {
var tree = new Mif.Tree({
container: $(tContainer),
forest: true, // tree does not have a root node
initialize: function() {
$(tFormField).dispose();
this.initCheckbox('partial', 'id', tFormField);
},
types: {
folder: {
openIcon: 'mif-tree-open-icon',
closeIcon: 'mif-tree-close-icon'
},
loader: {
openIcon: 'mif-tree-loader-open-icon',
closeIcon: 'mif-tree-loader-close-icon',
DDnotAllowed: ['inside','after']
}
},
dfltType: 'folder',
height: 18
});
tree.load({json: data[tTreeData]});
tree.loadOptions=function(node){
var options = {};
if (node.id) {
options.url = tAjaxUri+node.id;
}
return options;
}
if (data && data.form_values && data.form_values[tFormField])
{
tree.setChecked(data.form_values[tFormField]);
}
tree.openLoaded();
return tree;
}