jsTree - 当复选框为 ticket 时调用函数并获取所有勾选的复选框
jsTree - Call function when checkbox is ticket and get all ticked checkboxes
有没有办法在 jstree 中勾选复选框时调用函数?
我有以下示例,并且想在树中的复选框被勾选时调用函数 "getImages" 并且我想收集此函数内所有勾选的复选框。知道怎么做吗?
$('#container').jstree({
"core": {
"themes":{ "icons":false },
'data' : [
{
"text" : "Root",
"children" : [
{ "id": 1, "text" : "Item A", "state" : { "opened" : true }, "children" : [ { "id": 11, "text" : "A-1"}, { "id": 12, "text" : "A-2"} ] },
{ "id": 2, "text" : "Item B" }
]
}
]
},
"checkbox" : {
"keep_selected_style" : false
},
"plugins" : [ "checkbox", "wholerow" ]
}
).on('ready.jstree', function(){ $(this).jstree('open_all') });
function getImages() {
// get all the id of all ticked checkboxes
}
来自 [
我自己的测试:
$(function () {
$('#container').jstree({
"core": {
"themes":{ "icons":false },
'data' : [
{
"text" : "Root",
"children" : [
{ "text" : "Item A", "state" : { "opened" : true }, "children" : [ "A-1", "A-2" ] },
{ "text" : "Item B" }
]
}
]
},
"checkbox" : {
"keep_selected_style" : false
},
"plugins" : [ "checkbox", "wholerow" ]
}
).on('ready.jstree', function(){ $(this).jstree('open_all') });
function getImages() {
console.log('ok');
}
$("#container").bind("changed.jstree",
function (e, data) {
//alert("Checked: " + data.node.id);
getImages();
//alert(JSON.stringify(data));
});
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" type="text/css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
<div id="container">test</div>
有没有办法在 jstree 中勾选复选框时调用函数? 我有以下示例,并且想在树中的复选框被勾选时调用函数 "getImages" 并且我想收集此函数内所有勾选的复选框。知道怎么做吗?
$('#container').jstree({
"core": {
"themes":{ "icons":false },
'data' : [
{
"text" : "Root",
"children" : [
{ "id": 1, "text" : "Item A", "state" : { "opened" : true }, "children" : [ { "id": 11, "text" : "A-1"}, { "id": 12, "text" : "A-2"} ] },
{ "id": 2, "text" : "Item B" }
]
}
]
},
"checkbox" : {
"keep_selected_style" : false
},
"plugins" : [ "checkbox", "wholerow" ]
}
).on('ready.jstree', function(){ $(this).jstree('open_all') });
function getImages() {
// get all the id of all ticked checkboxes
}
来自 [
我自己的测试:
$(function () {
$('#container').jstree({
"core": {
"themes":{ "icons":false },
'data' : [
{
"text" : "Root",
"children" : [
{ "text" : "Item A", "state" : { "opened" : true }, "children" : [ "A-1", "A-2" ] },
{ "text" : "Item B" }
]
}
]
},
"checkbox" : {
"keep_selected_style" : false
},
"plugins" : [ "checkbox", "wholerow" ]
}
).on('ready.jstree', function(){ $(this).jstree('open_all') });
function getImages() {
console.log('ok');
}
$("#container").bind("changed.jstree",
function (e, data) {
//alert("Checked: " + data.node.id);
getImages();
//alert(JSON.stringify(data));
});
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" type="text/css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
<div id="container">test</div>