Обтекание листового текста в jstree
Я использую jstree plugin для заполнения моего дерева на основе xml файла. Текст некоторых узлов больше, чем контейнер div. Есть ли способ текстового переноса jstree node текстов?
$(document).ready(function(){
$("#tree").jstree({
"xml_data" : {
"ajax" : {
"url" : "jstree.xml"
},
"xsl" : "nest"
},
"themes" : {
"theme" : "classic",
"dots" : true,
"icons" : true
},
"search" : {
"case_insensitive" : true,
"ajax" : {
"url" : "jstree.xml"
}
},
"plugins" : ["themes", "xml_data", "ui","types", "search"]
}).bind("select_node.jstree", function (event, data) {
$("#tree").jstree("toggle_node", data.rslt.obj);
Ответы
Ответ 1
Это сработало для 3.0.8
.jstree-anchor {
/*enable wrapping*/
white-space : normal !important;
/*ensure lower nodes move down*/
height : auto !important;
/*offset icon width*/
padding-right : 24px;
}
И для тех, кто использует плагин wholerow
;
//make sure the highlight is the same height as the node text
$('#tree').bind('hover_node.jstree', function() {
var bar = $(this).find('.jstree-wholerow-hovered');
bar.css('height',
bar.parent().children('a.jstree-anchor').height() + 'px');
});
Для 3.1.1 и для того, чтобы он также работал с select_node.jstree
используйте эту функцию вместо:
function(e, data) {
var element = $('#' + data.node.id);
element
.children('.jstree-wholerow')
.css('height', element.children('a').height() + 'px')
;
}
Ответ 2
Попробуйте добавить следующий стиль к дочерним якорям вашего div jsTree:
#jstree_div_id a {
white-space: normal !important;
height: auto;
padding: 1px 2px;
}
У меня также есть max-width для моего стиля jsTree div:
#jstree_div_id
{
max-width: 200px;
}
Ответ 3
#tree_id {
.jstree-anchor {
white-space: normal;
height: auto;
}
.jstree-default .jstree-anchor {
height: auto;
}
}
Ответ 4
Я нашел ответ по coincedence, и это сработало для меня, но у меня было другое правило css, которое мешало корректному функционированию кода
Я удалил правило css (min-height: 200px) "в моем коде", и следующий ответ работал у меня, как я ожидал.
#tree_div_id a {
white-space: normal;
height: auto;
padding: 0.5ex 1ex;
margint-top:1ex;
}
Ответ 5
Объединение ответов от Hashbrown и TwiceB, чтобы заставить его работать с плагином wholerow и предварительно выбранными данными.
Включить перенос текста
.jstree-anchor {
/*enable wrapping*/
white-space : normal !important;
/*ensure lower nodes move down*/
height : auto !important;
/*offset icon width*/
padding-right : 24px;
}
Включите выделение обернутого текста при наведении курсора и выберите
$('#tree').bind('open_node.jstree', function () {
let bar = $(this).find('.jstree-wholerow-clicked');
bar.css('height',
bar.parent().children('a.jstree-anchor').height() + 'px');
});
$('#tree').bind('hover_node.jstree', function () {
var bar = $(this).find('.jstree-wholerow-hovered');
bar.css('height',
bar.parent().children('a.jstree-anchor').height() + 'px');
});