2016-05-04 5 views
1

nach dem Lesen von Threads und Lösen eines Problems nach dem anderen. Ich stapeln bei einem großen Problem, es gibt keine Ausgabe.Bootstrap Tree View funktioniert nicht - übergeben Objekt noch keine Ausgabe

Wie ich bereits erwähnt verwende ich Bootstrap Baumansicht:

Um die hierarchische Struktur für den Baum ist es erforderlich zu definieren, notwendig, um eine verschachtelte Array von JavaScript-Objekten zur Verfügung zu stellen.

Beispiel

var tree = [ 
     { 
     text: "Parent 1", 
     nodes: [ 
      { 
      text: "Child 1", 
      nodes: [ 
       { 
       text: "Grandchild 1" 
       }, 
       { 
       text: "Grandchild 2" 
       } 
      ] 
      }, 
      { 
      text: "Child 2" 
      } 
     ] 
     }, 
     { 
     text: "Parent 2" 
     }, 
     { 
     text: "Parent 3" 
     }, 
     { 
     text: "Parent 4" 
     }, 
     { 
     text: "Parent 5" 
     } 
    ]; 

Output My Category Array:

Array 
(
    [0] => Array 
     (
      [text] => Housing 
      [href] => http://localhost/projekte/application/housing/housing 
      [tags] => ['5'] 
      [nodes] => Array 
       (
        [0] => Array 
         (
          [text] => House 
          [href] => http://localhost/projekte/application/house/house 
          [tags] => ['20'] 
         ) 

        [1] => Array 
         (
          [text] => Shared Apartments - Rooms 
          [href] => http://localhost/projekte/application/shared-apartments-rooms/shared-apartments-rooms 
          [tags] => ['19'] 
         ) 

        [2] => Array 
         (
          [text] => Apartment 
          [href] => http://localhost/projekte/application/apartment/apartment 
          [tags] => ['18'] 
         ) 

       ) 

     ) 

    [1] => Array 
     (
      [text] => Jobs 
      [href] => http://localhost/projekte/application/jobs/jobs 
      [tags] => ['2'] 
      [nodes] => Array 
       (
        [0] => Array 
         (
          [text] => Full Time 
          [href] => http://localhost/projekte/application/full-time/full-time 
          [tags] => ['7'] 
         ) 

        [1] => Array 
         (
          [text] => Part Time 
          [href] => http://localhost/projekte/application/part-time/part-time 
          [tags] => ['8'] 
         ) 

        [2] => Array 
         (
          [text] => Internship 
          [href] => http://localhost/projekte/application/internship/internship 
          [tags] => ['9'] 
         ) 

        [3] => Array 
         (
          [text] => Au pair 
          [href] => http://localhost/projekte/application/au-pair/au-pair 
          [tags] => ['10'] 
         ) 

       ) 

     ) 

    [2] => Array 
     (
      [text] => Languages 
      [href] => http://localhost/projekte/application/languages/languages 
      [tags] => ['3'] 
      [nodes] => Array 
       (
        [0] => Array 
         (
          [text] => English 
          [href] => http://localhost/projekte/application/english/english 
          [tags] => ['11'] 
         ) 

        [1] => Array 
         (
          [text] => Spanish 
          [href] => http://localhost/projekte/application/spanish/spanish 
          [tags] => ['12'] 
         ) 

        [2] => Array 
         (
          [text] => Other Languages 
          [href] => http://localhost/projekte/application/other-languages/other-languages 
          [tags] => ['13'] 
         ) 

       ) 

     ) 

    [3] => Array 
     (
      [text] => Friendship 
      [href] => http://localhost/projekte/application/friendship/friendship 
      [tags] => ['17'] 
     ) 

    [4] => Array 
     (
      [text] => Market 
      [href] => http://localhost/projekte/application/market/market 
      [tags] => ['6'] 
      [nodes] => Array 
       (
        [0] => Array 
         (
          [text] => TV 
          [href] => http://localhost/projekte/application/tv/tv 
          [tags] => ['21'] 
         ) 

        [1] => Array 
         (
          [text] => Audio 
          [href] => http://localhost/projekte/application/audio/audio 
          [tags] => ['22'] 
         ) 

        [2] => Array 
         (
          [text] => Furniture 
          [href] => http://localhost/projekte/application/furniture/furniture 
          [tags] => ['23'] 
         ) 

        [3] => Array 
         (
          [text] => IT 
          [href] => http://localhost/projekte/application/it/it 
          [tags] => ['24'] 
         ) 

        [4] => Array 
         (
          [text] => Other Market 
          [href] => http://localhost/projekte/application/other-market/other-market 
          [tags] => ['25'] 
         ) 

       ) 

     ) 

    [5] => Array 
     (
      [text] => Others 
      [href] => http://localhost/projekte/application/others/others 
      [tags] => ['4'] 
      [nodes] => Array 
       (
        [0] => Array 
         (
          [text] => Events 
          [href] => http://localhost/projekte/application/events/events 
          [tags] => ['14'] 
         ) 

        [1] => Array 
         (
          [text] => Hobbies 
          [href] => http://localhost/projekte/application/hobbies/hobbies 
          [tags] => ['15'] 
         ) 

        [2] => Array 
         (
          [text] => Services 
          [href] => http://localhost/projekte/application/services/services 
          [tags] => ['16'] 
         ) 

       ) 

     ) 

) 

Dies ist der Code, der den Baum angezeigt werden soll:

<div class="treeview" id="treeview1"> 
      <ul class="list-group"> 
      </ul> 
     </div> 
     <script type='text/javascript'> 
      var js_data = <?php json_encode($tree,JSON_FORCE_OBJECT) ?>; 
      var js_obj_data = JSON.parse(js_data); 
      function getTree() { 
       return js_obj_data; 
      } 
      $('#treeview1').treeview({data: getTree()}); 
     </script> 

HINWEIS: Ich fand alle Fäden habe ich gelesen keine Antwort auf mein Problem. Dank

Antwort

0

Lösung:

<script type='text/javascript'> 
     $(function() { 
      var js_data = <?php echo json_encode($tree,JSON_PRETTY_PRINT) ?>; 
      // var js_obj_data = JSON.parse(js_data); 
     // alert(js_data.toSource); 
     function getTree() { 
      return js_data; 
     } 
     $('#treeview1').treeview({data: getTree()}); 
     }); 
    </script> 
Verwandte Themen