2013-02-25 14 views
12

Sto usando il plugin jstree per popolare il mio albero in base al file xml. Il testo di alcuni nodi è maggiore del div contenitore. C'è un modo per avvolgere i testi dei nodi jstree?testo foglia wrapping in jstree

$(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); 

risposta

10

Prova ad aggiungere il seguente stile per il bambino ancore del vostro jsTree div:

#jstree_div_id a { 
    white-space: normal !important; 
    height: auto; 
    padding: 1px 2px; 
} 

Ho anche un max-width sulla mia jsTree div styling:

#jstree_div_id 
{ 
    max-width: 200px; 
} 
+1

Grazie È un lavoro eccellente per me –

+0

Grazie mille! Funziona perfettamente per me! – Tung

1
#tree_id { 
    .jstree-anchor { 
    white-space: normal; 
    height: auto; 
    } 
    .jstree-default .jstree-anchor { 
    height: auto; 
    } 
} 
9

Questo ha funzionato per 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; 
} 

E per coloro che utilizzano il plug-in 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'); 
}); 
+0

Il suggerimento del plugin 'wholerow' era quello che stavo cercando. – SNag

+0

Ottima risposta! Questo ha funzionato per me, ma per gli alberi che avevano dati preselezionati, non è così. Ho usato il seguente:
'$ (# tree '). Bind' open_node.jstree ', ->'
'bar = $ (this) .find ('. Jstree-wholerow-clicked ')'
' bar.css 'height', bar.parent(). children ('a.jstree-anchor'). height() + 'px'' – TwiceB

0

ho trovato la risposta da coincedence e ha funzionato per me, ma, ho avuto un'altra regola CSS che impediva il codice di funzionare bene

ho rimosso la regola CSS (min-height: 200px) "nel mio codice" e la risposta seguente ha funzionato per me come mi aspettavo.

#tree_div_id a { 
white-space: normal; 
height: auto; 
padding: 0.5ex 1ex; 
margint-top:1ex; 
}