The RadTreeNode js class has the function toJsonString, but what good is it without a function to deserialize it back into a RadTreeNode object.
I tried using _loadFromDictionary but it didn't seem to work and it is a private method.
Am I missing something?
Thanks
3 Answers, 1 is accepted
0
Atanas Korchev
Telerik team
answered on 03 Sep 2009, 06:46 AM
Hi Roatin Marth,
The usage of the toJsonString method is shown in this example. There the string is used on the server-side. Currently the _loadFromDictionary method accepts a JSON object rather than string so it cannot be used. Could you please let us know your requirements?
I need to be able to serialize and deserialize a node on the client side. I have a node with several attributes, text, image etc. that I need the app to be able to remember. Whats happening is I'm working on a page that still uses post backs in some cases which causes the client side state to be wiped out. So I'm serializing this special node (It's not a selected node, just a special node I want to remember) and sticking it in a hidden field so after a postback I have the ability to bring it back into the client side.
However at this point there is no equivalent function to deserialize in the client side. So thats what I'm missing.
By the way I tried calling Sys.Serialization.JavaScriptSerializer.deserialize() before _loadFromDictionary and it still didn't work.
Thanks
0
Atanas Korchev
Telerik team
answered on 04 Sep 2009, 08:47 AM
Hello Roatin Marth,
Find below some sample code which works as expected at my side:
<script type="text/javascript">
function pageLoad(){
var treeView = $find("<%= RadTreeView1.ClientID %>");
var firstNode = treeView.get_nodes().getNode(0);
var jsonAsString = firstNode.toJsonString();
alert(jsonAsString);
var node = new Telerik.Web.UI.RadTreeNode();
node._loadFromDictionary(Sys.Serialization.JavaScriptSerializer.deserialize(jsonAsString));
firstNode.get_nodes().add(node);
}
</script>