首頁 >後端開發 >php教程 >javascript - Laravel生成jstree的json数据

javascript - Laravel生成jstree的json数据

WBOY
WBOY原創
2016-07-06 13:52:121258瀏覽

laravel从数据库中取出来的数据如何封装成jstree能够读取的模型?如果有能给个实例就好了……

<code>$("#tree_4").jstree({
    core: {
        themes: {
            responsive: !1
        },
        check_callback: !0,
        data: {
            url: function (e) {
                return "{{ route('api.deparment') }}"
            },
            data: function (e) {
                return {
                    parent: e.id
                }
            }
        }
    },
    types: {
        "default": {
            icon: "fa fa-folder icon-state-warning icon-lg"
        },
        file: {
            icon: "fa fa-file icon-state-warning icon-lg"
        }
    },
    state: {
        key: "demo3"
    },
    plugins: ["dnd", "state", "types"]
})</code>

回复内容:

laravel从数据库中取出来的数据如何封装成jstree能够读取的模型?如果有能给个实例就好了……

<code>$("#tree_4").jstree({
    core: {
        themes: {
            responsive: !1
        },
        check_callback: !0,
        data: {
            url: function (e) {
                return "{{ route('api.deparment') }}"
            },
            data: function (e) {
                return {
                    parent: e.id
                }
            }
        }
    },
    types: {
        "default": {
            icon: "fa fa-folder icon-state-warning icon-lg"
        },
        file: {
            icon: "fa fa-file icon-state-warning icon-lg"
        }
    },
    state: {
        key: "demo3"
    },
    plugins: ["dnd", "state", "types"]
})</code>

laravel 查询出的结果 直接进行 toJson() 即可

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn