Jstree-如何正确放置在模板上

时间:2018-07-10 16:20:02

标签: html jstree placement

如何在模板上正确地将jsTree居中?我试图只使用

,但是却得到了这样的内容 enter image description here

如图所示,很难看到哪个节点是子节点/父节点。 我喜欢它在https://www.jstree.com/(右边的正方形)上的制作方式。

模板代码(我认为是否需要):

<html>

<head>
    <title>XLS</title>
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jstree/3.3.5/themes/default/style.min.css" />
</head>

<body onload="PathInit()">
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/jstree/3.3.5/jstree.min.js"></script>
    <br><br><br><br>
    <center>
        <br><b>Select a directory.<br></b></center><br><br>
    <script>
        function PathInit() {
            $.get("/xls/path/", {
                path: ""
            });
        }

    </script>
    <center>
        <div id="container" name="container">
            //Way to many
            <ul>'s and
                <li>'s
        </div>
        <script>
            function myf(a) {
                return a.instance.get_selected(true)[0].text;
            }
            var tree = $('#container')
                .jstree();
            $('#container')
                .on("changed.jstree", function(e, data) {
                    var elo = window.myf(data);
                    console.log(elo);
                    $.get("/xls/path/", {
                        path: elo
                    });
                });

        </script>


        <center><br>
            <form method="post">

                <br><br><b>Select source language:
                    <br>
                    <select name="source" id="source" option selected>
                        {% for o in data %}
                        <option value="{{o.name}}">{{o.full}}</option>

                        {% endfor %}
                    </select>

                    <br>
                    <br>Select destionation languages:<br></b>
                (hold ctrl to add more items)<br>
                <select multiple name="args[]" id="args" size="10">
                    {% for o in data %}
                    <option value="{{o.name}}">{{o.full}}</option>
                    {% endfor %}
                </select>

                <br><br><br>


                <input type="submit" value="Send"><br><br></form>
            <a href="/index/">Back</a>
        </center>
</body>

</html>

1 个答案:

答案 0 :(得分:0)

对齐问题是由于html center标签无法与jsTree的CSS样式很好地配合使用。一种方法是从中心标记中删除树Div并将其与一些自定义CSS对齐。

<div id="container" name="container" style="margin-left: auto; margin-right: auto; display: table">
        //Way to many <ul>'s and <li>'s
</div>