Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery EasyUI Tree Menu - Loading Parent/Child Nodes in a Tree Menu

jQuery EasyUI Tree Menu - Loading Parent/Child Nodes in a Tree Menu

The usual way to represent a tree node is to store a parentid in each node. This is also known as the adjacency list model. It is not allowed to load such data directly into a Tree menu. But we can convert it to the standard Tree menu data format before loading the Tree menu. The Tree plugin provides a 'loadFilter' option function that can do this. It provides an opportunity to alter any incoming data. This tutorial shows you how to use the 'loadFilter' function to load parent/child nodes into a Tree menu.

Parent/child node data



    [

    {"id":1,"parendId":0,"name":"Foods"},

    {"id":2,"parentId":1,"name":"Fruits"},

    {"id":3,"parentId":1,"name":"Vegetables"},

    {"id":4,"parentId":2,"name":"apple"},

    {"id":5,"parentId":2,"name":"orange"},

    {"id":6,"parentId":3,"name":"tomato"},

    {"id":7,"parentId":3,"name":"carrot"},

    {"id":8,"parentId":3,"name":"cabbage"},

    {"id":9,"parentId":3,"name":"potato"},

    {"id":10,"parentId":3,"name":"lettuce"}

    ]

Creating a Tree using 'loadFilter'



    $('#tt').tree({

        url: 'data/tree6_data.json',

        loadFilter: function(rows){

            return convert(rows);

        }

    });

The conversion implementation



    function convert(rows){

        function exists(rows, parentId){

            for(var i=0; i

Download the jQuery EasyUI example

jeasyui-tree-tree6.zip