Re 1)
For callbacks that pass the node as argument, please let us pass real
objects with the node not only string name-value pairs.
In JSON, data for a node is passed in attributes as String name-value
pairs.
We could try to pass an object not a string as follows (does not
work):
var myDataObject = {keyValue:3, name:"Peter", phoneNumber:"1234567"};
data : {
title : "Long format demo",
attributes : { "href" : "
http://jstree.com", "myDataObject",
myDataObject}
}
A callback could get the data for a node as follows:
callback : {
onselect : function (NODE, TREE_OBJ) {
// We are accessing a DOM methods - not any jsTree node object
method
var atts = NODE.attributes;
alert("NODE.attributes = " + atts);
var attribute = atts.getNamedItem("myDataObject");
alert("attribute = " + attribute);
alert("
attribute.name = " +
attribute.name);
var myObject = attribute.value
// We cannot get a non-string data object from a DOM
attribute. This is HTML, not data
// THIS IS THE DEAD END - NO OBJECTS ARE SUPPORTED HERE
alert("myObject.phoneNumber = " + myObject.phoneNumber);
}
}
Normally with GUIs, there is a model and a view.
With jsTree, the view is HTML.
When using JavaScript/JSON, the model would typically be in
JavaScript.
I guess, that with jsTree, the model is in JavaScript, too.
Applications of jsTree using JSON, implicitely have their tree object
model in JSON already, whether that is part of application design or
not.
We are now counting THREE more or less complete copies of the model:
JSON, jsTree, and HTML.
The model IS also in HTML as documented in jsTree documentation:
"As you can see you can pass any attributes you like in the attributes
object - in the resulting HTML output those attributes are bound to
the <li> element."
It would be so much easier to use JavaScript with jsTree if the bound
objects of a user model could be passed back with all callbacks.