dqbn76906 2019-04-04 16:47
浏览 91

回显默认情况下使用PHP检查的JSTree列表项

The question is very simple, im trying to echo with PHP a JSTree List Item that is checked by default.

According to all the information that i've found on similar issues, I should be able to echo an active list item by just adding class="jstree-checked" but its not working for me.

This is the code that I'm currently using. This code shows up a list item that is not checked.

echo '<li class="jstree-checked" id="id">List Item that should be checked on load but its not</li>';

This is my JS Tree code

    <script>    
    var select_data = '';

    $(function () {
        $("#tree").jstree({
            "checkbox": {
                'keep_selected_style': false,
'three_state': false,
'cascade': '',
            },
                "plugins": ["checkbox"],    
        });
        $("#tree").bind("changed.jstree",
            function (e, data) {
                console.log(data);

                select_data = JSON.stringify(data.selected);

            }
        );
    }); 


    $.jstree._reference('#tree').check_node('#test'); 

    function upload() {

        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                alert(this.responseText);
            }
        };

        var url = "../../jstree/ajax.php?select_data=" + select_data;

        xhttp.open("GET", url, true);
        xhttp.send(); 
    }
    </script> 
  • 写回答

1条回答 默认 最新

  • dongpao1083 2019-04-04 18:17
    关注

    My goal is to show a single node with a mix of checked/non-checked list items, but since I still didn't manage to fix this, i found out a temporary solution.

    I'm echoing two different nodes, one for the list items that should be checked, and another one for the list items that should not be checked.

    After that, I just added this to the script:

    $(function(){
    $('#tree').jstree(true).select_node('active_items_node');
    });  
    

    With this little function, my #active_items_node will load up on default checked state.

    评论

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序