怎么在jstree中實現checkbox默認選中和隱藏?相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。
首先需要配置 Checkbox plugin
"plugins" : ['checkbox']
設置默認選中狀態(checkbox 選中)
state: {checked: true}
$.jstree.defaults.checkbox.tie_selection示例:
$('#demo_tree').jstree({
"core" : {
'data': [
{ "id" : "ajson1", "parent" : "#", "text" : "Simple root node", state: {checked: true}},
{ "id" : "ajson2", "parent" : "#", "text" : "Root node 2" },
{ "id" : "ajson3", "parent" : "ajson2", "text" : "Child 1" },
{ "id" : "ajson4", "parent" : "ajson2", "text" : "Child 2" },
]
},
"plugins" : ['checkbox'],
"checkbox" : {
"tie_selection": false,
}
});jstree復選框自定義顯示隱藏
jstree 本身不支持在節點中隱藏 checkbox,國外有個大佬給出一個利用 css 來隱藏的解決方案:
首先來一段 css
.no_checkbox>i.jstree-checkbox{display:none}然后在 data 的 json 數據結構中
$('#demo_tree').jstree({
"core" : {
'data': [
{ "id" : "ajson1", "parent" : "#", "text" : "Simple root node", state: {checked: true}},
{ "id" : "ajson2", "parent" : "#", "text" : "Root node 2" },
{ "id" : "ajson3", "parent" : "ajson2", "text" : "Child 1" , a_attr: {class: "no_checkbox"}},
{ "id" : "ajson4", "parent" : "ajson2", "text" : "Child 2" },
]
},
"plugins" : ['checkbox'],
});效果:
jstree version => 3.3.8
看完上述內容,你們掌握怎么在jstree中實現checkbox默認選中和隱藏的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。