问题很简单,我试图用PHP回显默认选中的JSTree列表项。
根据我在类似问题上发现的所有信息,我应该能够通过添加class="jstree-checked"
来回显活动列表项,但对我不起作用。
这是我当前正在使用的代码。 此代码显示未选中的列表项。
echo '<li class="jstree-checked" id="id">List Item that should be checked on load but its not</li>';
这是我的JS树代码
<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>
答案 0 :(得分:0)
我的目标是显示包含已检查/未检查列表项的单个节点,但是由于我仍然无法解决此问题,因此我找到了一个临时解决方案。
我回显了两个不同的节点,一个用于应检查的列表项,另一个用于不应检查的列表项。
之后,我将其添加到脚本中:
$(function(){
$('#tree').jstree(true).select_node('active_items_node');
});
有了这个小功能,我的#active_items_node将在默认检查状态下加载。