douzhun5971 2017-09-27 16:16
浏览 129
已采纳

JsTree和Laravel麻烦

I'm following this guide to setup JsTree with lazy load using Ajax in my Laravel 5.5 app .

This is my controller: https://gist.github.com/aaronr0207/7fa0a38f40bfd2f728a15d655254f82d

My View: https://gist.github.com/aaronr0207/f87720263e3d6026b04b00c08bae5cb2

My JsTree class is exactly the same I didn't make any change.

Actually I'm getting the following error on chrome's console:

d9973d3e-1476-4453-a013-9e9c8430bcba:1 Uncaught TypeError: Cannot read property 'children' of undefined

enter image description here

But when I dump the response to debug it (at the end of TreeViewController data method):

        dd(response()->json($tree->build()));

It works...

enter image description here

My response looks like this (when I die-dump it):

enter image description here

Any idea? Thank you

EDIT1: If I return a simple json_encode($tree->build) there are no errors but it shows an empty tree... and the response looks like this:

enter image description here

EDIT2: got it! But now there are a new issue... All I did to solve it was change the url string with a callback:

 $('#jstree').jstree({
    'core': {
        'data': {
            'url': function (node) {
                return '{!! route('tree.data') !!}' ;
            },
            'data': function (node) {
                console.log(node);
                return {'id': node.id};
            }
        }
    }
});

But now when I fetch next level directories, if they have another directorie inside it fails without error:

enter image description here

Test1 content is the following:

enter image description here

If I delete test1/test2 folder, it works showing:

enter image description here

Same when I delete the txt file...What is happening now? Maybe this is a new question so I'll post my solution to the main problem and I'll accept it.

  • 写回答

3条回答 默认 最新

  • douniangliao4327 2017-09-29 08:43
    关注

    got it! All I did to solve it was change the url string with a callback:

    $('#jstree').jstree({
        'core': {
            'data': {
                'url': function (node) {
                    return '{!! route('tree.data') !!}' ;
                },
                'data': function (node) {
                    console.log(node);
                    return {'id': node.id};
                }
            }
        }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?