In order to store arbitrary data in jsTree nodes, I'm passing a custom attribute (say node-data) to the create_node method. But I need to store more than one piece of data in the single attribute. (For example name,age etc.) What format would be best suited for the value of the node-data attribute? What I'm looking for is a format that will allow easy retrieval of data.
For example we can have a format like "name:John,age:26". But I will have to split the string by using the comma as the delimiter and split at the colon to separate the name and value. Is there a better way to do this?
Any reason you're not using data- attributes? Supported by jquery and every current browser (HTML5). So instead of obj.attr("myattrib", true); You can assign arbitrary data to any object. You could easily do things like:
node.data("name", "John");
node.data("age", 26);
and later you retrieve them when needed:
var name = node.data("name");
on the server end, presuming you're sending your data back as Json data, you simply define (in the simplest form, you can get fancier) a Dictionary metadata in the json object in the server, then you retrieve "name" from the dictionary, cast the object to the appropriate type and away you go!