Heim  >  Fragen und Antworten  >  Hauptteil

javascript - jstree 使用问题,老是无法生成树形菜单

参照官方Demo, 使用 异步获取 数据,生成 树形菜单,老是无法显示出来。。。。

    <p id="container" role="main">
        <p id="tree"></p>
        <p id="data">
            <p class="content code" style="display:none;"><textarea id="code" readonly="readonly"></textarea></p>
            <p class="content folder" style="display:none;"></p>
            <p class="content image" style="display:none; position:relative;"><img src="" alt="" style="display:block; position:absolute; left:50%; top:50%; padding:0; max-height:90%; max-width:90%;" /></p>
            <p class="content default" style="text-align:center;">Select a node from the tree.</p>
        </p>
    </p>

    <script>
        $(function () {
            
            $('#tree').jstree({
                    'core' : {
                        'data' : {
                            'url' : 'jstree.php?operation=get_node',
                            'data' : function (node) {
                                return { 'id' : node.id };
                            }
                        },
                        'force_text' : true,
                        'check_callback' : true,
                        'themes' : {
                            'responsive' : false
                        }
                    },
                    'plugins' : ['state','dnd','contextmenu','wholerow']
                })
        });
    </script>

jstree.php 文件输出 JSON 格式字符串,如: [{"id":1,"text":"Amanullah TVL1","children":false}]

页面上总是空白,无法调试成功,求帮助。。。

伊谢尔伦伊谢尔伦2721 Tage vor375

Antworte allen(1)Ich werde antworten

  • PHPz

    PHPz2017-04-11 13:03:16

    已自己解决

    $('#tree').jstree({
            'core' : {
                'data' : {
                    'dataType': 'json',  // 加上这句就好了
                     ... ...
                }
            }
        });

    Antwort
    0
  • StornierenAntwort