I want to pass data from fancytree to a common handler to save it for future use.
If I use this code:
function SaveTree() {
var tree = $('#TopTree').fancytree("getTree");
$.ajax({
cache: false,
url: "SaveTree.ashx",
data: { 'treeData': tree },
contentType: "application/json; charset=utf-8"
});
}
Then I get the following error from jquery.js:
JavaScript runtime error: Argument not optional
I also tried:
var tree = $('#TopTree').fancytree("getTree").rootNode.children;
This gives the same error. I understand this because the "tree" is not JSON. How to convert data to a JSON object?
EDIT:
If I use this code:
function SaveTree() {
var data = [];
var tree = $('#TopTree').fancytree("getTree").rootNode.children;
for (var i = 0; i < tree.length; i++) {
data.push(tree[i].title)
}
data = JSON.parse(JSON.stringify(data))
$.ajax({
cache: false,
url: "SaveTree.ashx",
data: { 'treeData': data },
contentType: "application/json; charset=utf-8"
});
}
I can get it to do what I need, but is there no built-in function for this in fancytree?
source
share