generic handler - Pass fancytree data as JSON data -
i want pass data fancytree generic handler can save future use.
if use code:
function savetree() { var tree = $('#toptree').fancytree("gettree"); $.ajax({ cache: false, url: "savetree.ashx", data: { 'treedata': tree }, contenttype: "application/json; charset=utf-8" }); }
then following error jquery.js:
javascript runtime error: argument not optional
i have tried:
var tree = $('#toptree').fancytree("gettree").rootnode.children;
this gives same error. understand because 'tree' not json. how can convert data json object?
edit:
if use code:
function savetree() { var data = []; var tree = $('#toptree').fancytree("gettree").rootnode.children; (var = 0; < 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 accomplish need, there not built-in function in fancytree?
okay, don't know lot fancytree; however, did investigation , found page http://wwwendt.de/tech/fancytree/demo/sample-api.html.
try tree.todict() option see if you're looking for.
this source code.
// convert whole tree dictionary var tree = $("#tree").fancytree("gettree"); var d = tree.todict(true); alert(json.stringify(d));
Comments
Post a Comment