weixin_33725126 2018-09-10 21:22 采纳率: 0%
浏览 39

fancytree单击上发布ajax

I'm using fancytree to create a tree structure from mysql data source...

https://github.com/mar10/fancytree/wiki

I want to update the db on change of this structure and this is my code

$("#tree").on("fancytreeclick", function(event, data){

  var nodes = $('#tree').fancytree("getTree").getSelectedNodes();
  console.log(nodes);

  $.ajax({
    type : 'POST',
    url  : 'call/myclass.php',
    data : {
      selected : nodes,
      tipo : "update",
    },
    success :  function(data) {
      // nothing
    },

    error: function(data) { 
      console.log(data);
    },
  });

});

but I'm getting this error

Uncaught RangeError: Maximum call stack size exceeded
at Function.isArray (<anonymous>)

Why this?

  • 写回答

1条回答 默认 最新

  • weixin_33705053 2018-09-12 05:46
    关注

    The method

    tree.getSelectedNodes()
    

    returns an array of FancytreeNode objects. You need to convert this to plain objects, so the $.ajax function can serialize it.

    For example iterate over the Array and use node.toDict():

    var selNodes = $("#tree").fancytree("getTree").getSelectedNodes();
    var selData = $.map(selNodes, function(n){
      return n.toDict();
    });
    
    评论

报告相同问题?