tree.setChildCalcMode: some suggestions

Some suggestions regarding setChildCalcMode():



1) Improve the documentation. What parameters does it take.



2) The child count appears in the node label as “[x]”, as in:



My node [3]



When the tree is serialized, this notation becomes part of the data!!! If one stores this into the backing store, the next time you load from it, you’ll get:



My Node [3] [3]



This behavior needs to be documented or, preferably, changed. tree.serialize() should strip this notation. As it is, I need to change my data layer to strip this off, which is non-trivial if I want the user to actually be able to use such notation IN THE DATA.



It seems to me that the best way to handle this is to change the internal structure of the tree and display this information in a field next to the node label. This solution could be generalized to allow us to display userdata for each node, as well.



Thanks,

Joel Finkel


Please, try to use the following approach in order to don’t include [x] to the serialization result:





tree.setChildCalcMode(“child”);
tree.registerXMLEntity("\[[^\]]*\]","");
tree.setSerializationLevel(false,false,true); /the 3rd parameter should be true/





The registerXMLEntity method allows to replace the value, which matches the 1st parameter, with the value defined in the second one.




Alex,

Thank you.  The solution works for tree.serializeTreeToJSON, as well, which is what I use.  The regular expression leaves trailing blanks, but that is easily trimmed at the data access layer.



However, there is one problem.  If the actual text in the tree is, for example:



      “Pogo Speaks [p. 10]”



then the data are stored incorrectly.



It seems to me that the child count is metadata, and I think it should be treated as such, and not intermingled with application data.  So, I still think that it should be moved to a different internal tree structure.



Thanks,
Joel


Unfortunately, currently there is no opportunity to do it.


But it is possible to apply the replacement only for the last [x] part of the item text:


tree.registerXMLEntity("\[[^\]]*\]$","");


Moreover you can set another template for the calc value:


tree.setChildCalcHTML(prefix,postfix);


for example tree.setChildCalcHTML("(",")");