使用 jsTree (pre1.0_fix_1),我想获取所有已检查项目的id
列表(或更好,{{1}的JSON对象}和每个选中项目的文本)。然后我会用这个做一个ajax调用。此外,这应该在任何时候检查或取消选中的状态发生变化时发生。
这就是我目前所拥有的:
id
这只是从容器的$(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
返回“颜色”。我在<div id="colors">
物体附近钓鱼,但没有在那里找到它(也许我错过了它?)
答案 0 :(得分:3)
为了获取已检查节点的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 +文本对象,您可以将它们发送到服务器。