gpt4 book ai didi

javascript - 试图在 jstree 中的 change_state 上获取已检查项目的列表

转载 作者:行者123 更新时间:2023-11-29 20:11:26 25 4
gpt4 key购买 nike

使用jsTree (pre1.0_fix_1),我想获得id的列表用于所有选中的项目(或者更好的是,带有 id 和每个选中项目的文本的 JSON 对象)。然后我会用这个进行ajax调用。此外,只要检查或取消检查的状态发生变化,就会发生这种情况。

这是我目前拥有的:

$(function(){

n = $('#colors').jstree({
"plugins": ["themes", "html_data", "checkbox"]
}).bind("change_state.jstree", function(e, data){
console.log($('#colors').jstree('get_selected').attr('id'));
});
});

这只是从容器的 id 返回“colors” : <div id="colors"> .我在 data 周围钓鱼对象,但没有在那里找到它(也许我错过了?)

最佳答案

为了获取已检查节点的 JSON,您应该使用 get_checked 而不是 get_selected。试试这个:

    var checked = $("#colors").jstree("get_checked",null,true);
var checked_json = [];
$(checked).each(function (i,node) {
var id = $(node).attr("id");
var text = $(node).attr("text");
var node_json = {
"id" : id,
"text" : text
};
checked_json.push(node_json);
});

之后 checked_json 将包含一个 id+text 对象数组,您可以将其发送到服务器。

关于javascript - 试图在 jstree 中的 change_state 上获取已检查项目的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9544820/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com