2

i'm using jsTree with json as the datasource from the server.

Why the jsTree do ajax request on every click on a node and even if the node doesn't have children the node is getting filled with children from the server(it takes the root data!).

How can I prevent that behavior?

Greg
  • 23,155
  • 11
  • 57
  • 79
Yair Nevet
  • 12,725
  • 14
  • 66
  • 108

1 Answers1

0

script:

 <script language="javascript" type="text/javascript">
    $(document).ready(function () {
        $(function () {
            $("#treeview").jstree({
                "json_data": {
                    "ajax": {
                        "url": "/Tree/Tree"
                    }
                },
                "plugins": ["themes", "json_data"]
            });
        });
    });
</script>

server side:

    public class TreeController : Controller
{
    //
    // GET: /Tree/

    public ActionResult Tree()
    {
        return Json(new jsTreeModel
        {
            data = "Parent",
            att = new JsTreeAttribute { id = 1 },
            state = "closed",
            children = new List<jsTreeModel> { new jsTreeModel { data = "Child", att = new JsTreeAttribute { id = 1 }, state = "closed" } }

        }, JsonRequestBehavior.AllowGet);
    }



}
public class jsTreeModel
{
    public string data { get; set; }
    public JsTreeAttribute att { get; set; }
    public string state { get; set; }
    public List<jsTreeModel> children { get; set; }
}

public class JsTreeAttribute
{
    public int id { get; set; }
}
Yair Nevet
  • 12,725
  • 14
  • 66
  • 108