如何在jstree中获取部分选择的parent id
How to get partially selected parent id in jstree
我正在使用 "jstree" 树视图 (Parent-Child) 结构 uisng 复选框并返回每个选定项目的 ID。但在这里我只得到 children 的 ID 而没有被选中 parent 的 ID。麻烦帮我也弄一下。
点击[enter code here
http://jsfiddle.net/2kwkh2uL/5807/ ]找到代码。
每个对象都带有一个名为 parent
的键,其中包含 id
。下面的答案:
$('#container').jstree({
'core' : {
'data' : [
{ "text" : "P1", "children" : [
{ "text" : "O11" },
{ "text" : "O12" },
{ "text" : "O13"}
]
},
{ "text" : "P2", "children" : [
{ "text" : "O21" },
{ "text" : "O22" },
{ "text" : "O23"}
]
},
]
},
"plugins" : ["checkbox"]
});
$('#submitdiv').show();
$('#submit').click(function(){
var selectedElmsIds = [];
var selectedElms = $('#container').jstree("get_selected", true);
$.each(selectedElms, function() {
selectedElmsIds.push(
{
id: this.id,
parent: this.parent
}
);
console.log('Id node: '+this.id);
console.log('Id parent: '+this.parent);
});
console.log(JSON.stringify(selectedElmsIds));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.3/jstree.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.3/themes/default/style.min.css">
<div id="container"></div>
<div id="submitdiv" style="display:none;position:absolute">
<button id="submit">submit</button>
</div>
Espero haberte ayudado, saludos.
PS: 抱歉我的英语不好,我会说西班牙语,而且我正在使用 google 翻译器。
我正在使用 "jstree" 树视图 (Parent-Child) 结构 uisng 复选框并返回每个选定项目的 ID。但在这里我只得到 children 的 ID 而没有被选中 parent 的 ID。麻烦帮我也弄一下。
点击[enter code here
http://jsfiddle.net/2kwkh2uL/5807/ ]找到代码。
每个对象都带有一个名为 parent
的键,其中包含 id
。下面的答案:
$('#container').jstree({
'core' : {
'data' : [
{ "text" : "P1", "children" : [
{ "text" : "O11" },
{ "text" : "O12" },
{ "text" : "O13"}
]
},
{ "text" : "P2", "children" : [
{ "text" : "O21" },
{ "text" : "O22" },
{ "text" : "O23"}
]
},
]
},
"plugins" : ["checkbox"]
});
$('#submitdiv').show();
$('#submit').click(function(){
var selectedElmsIds = [];
var selectedElms = $('#container').jstree("get_selected", true);
$.each(selectedElms, function() {
selectedElmsIds.push(
{
id: this.id,
parent: this.parent
}
);
console.log('Id node: '+this.id);
console.log('Id parent: '+this.parent);
});
console.log(JSON.stringify(selectedElmsIds));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.3/jstree.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.3/themes/default/style.min.css">
<div id="container"></div>
<div id="submitdiv" style="display:none;position:absolute">
<button id="submit">submit</button>
</div>
Espero haberte ayudado, saludos.
PS: 抱歉我的英语不好,我会说西班牙语,而且我正在使用 google 翻译器。