2013-09-21 6 views
5

tworzę treepanel i ja i tworzyć store jakExtjs4.2.1 - Obciążenie json do treepanel nie

  var store = Ext.create('Ext.data.TreeStore', { 
      autoload: false, 
      proxy: { 
       type: 'ajax', 
       url: 'data.php', 
       reader: { 
        type: 'json', 
        root: 'results'     
       } 
      } 
      }); 

mój serwer druku json wyglądać

{ "results": 
    [ 
    { id : '1' , text : '1', expanded: true, 
     children :[ 
      { id : '5' , text : '5', leaf:true}, 
      { id : '6' , text : '6', leaf:true} 
     ] 
    }, 
    { id : '2' , text : '2', leaf:true}, 
    { id : '3' , text : '3', leaf:true}, 
    { id : '4' , text : '4', leaf:true}, 
    { id : '7' , text : '7', leaf:true}, 
    { id : '8' , text : '8', leaf:true}, 
    { id : '9' , text : '9', leaf:true}, 
    { id : '10' , text : '10', expanded: true, 
     children :[ 
      { id : '11' , text : '11', leaf:true}, 
      { id : '12' , text : '12', leaf:true} 
     ] 
    } 
    ] 
} 

Ale gdy uruchamiam mojego kodu, zobacz firebug i zawsze uruchamiaj GET http://localhost/example/data.php... nigdy nie przestawaj :(

i moje drzewo jest dodawane tak dużo podwójnie

Jak naprawić podziękować

Edycja
W prawdziwym ja definiować moje treepanel z aliasu i używając go jako xtype
Ale tworzę nowy przykład i uzyskać ten sam problem. Tu jest mój js

var store = Ext.create('Ext.data.TreeStore', { 
      autoload: false, 
      proxy: { 
       type: 'ajax', 
       url: 'data.php', 
       reader: { 
        type: 'json', 
        root: 'results'     
       } 
      } 
     }); 

     Ext.create('Ext.tree.Panel', { 
      title: 'Simple Tree', 
      width: 200, 
      height: 150, 
      store: store, 
      rootVisible: false, 
      renderTo: Ext.getBody() 
     }); 

A oto mój data.php

echo " 
{ 
    'success': true, 
    'variable': 100, 
    'results': 
    [ 
    { id : '1' , text : '1', expanded: true, 
     children :[ 
      { id : '5' , text : '5', leaf:true}, 
      { id : '6' , text : '6', leaf:true} 
     ] 
    }, 
    { id : '2' , text : '2', leaf:true}, 
    { id : '3' , text : '3', leaf:true}, 
    { id : '4' , text : '4', leaf:true}, 
    { id : '7' , text : '7', leaf:true}, 
    { id : '8' , text : '8', leaf:true}, 
    { id : '9' , text : '9', leaf:true}, 
    { id : '10' , text : '10', expanded: true, 
     children :[ 
      { id : '11' , text : '11', leaf:true}, 
      { id : '12' , text : '12', leaf:true} 
     ] 
    } 
    ] 
}"; 

Odpowiedz

5

Co masz tutaj jest coś uważam za błąd w treestore. Po zmianie czytnika na root, który nie jest children, należy również zmienić każdą instancję nazwy właściwości podrzędnych w danych na nową nazwę. Oznacza to, że jeśli chcesz zmienić korzeń do results, dane drzewo faktycznie muszą wyglądać tak:

echo " 
{ 
    'success': true, 
    'variable': 100, 
    'results': 
    [ 
    { 'id' : '1' , 'text' : '1', 'expanded': true, 
     'results':[ 
      { 'id' : '5' , 'text' : '5', 'leaf':true}, 
      { 'id' : '6' , 'text' : '6', 'leaf':true} 
     ] 
    }, 
    { 'id' : '2' , 'text' : '2', 'leaf':true}, 
    { 'id' : '3' , 'text' : '3', 'leaf':true}, 
    { 'id' : '4' , 'text' : '4', 'leaf':true}, 
    { 'id' : '7' , 'text' : '7', 'leaf':true}, 
    { 'id' : '8' , 'text' : '8', 'leaf':true}, 
    { 'id' : '9' , 'text' : '9', 'leaf':true}, 
    { 'id' : '10' , 'text' : '10', 'expanded': true, 
     'results':[ 
      { 'id' : '11' , 'text' : '11', 'leaf':true}, 
      { 'id' : '12' , 'text' : '12', 'leaf':true} 
     ] 
    } 
    ] 
}"; 

Inną opcją jest zmiana najwyższym poziomie results nazwę właściwości do children i oznaczyć pierwiastek Twój sklep jako children.

+1

To zajęło mi trochę czasu, aby ten rysunek początkowo, ponieważ zachowanie nie ma sensu. użyj tony drzew w naszej aplikacji – Reimius

+0

to problem dzięki u :) – freestyle

1

sprawdzić autoLoad config pisowni.

var store = Ext.create('Ext.data.TreeStore', { 
     // autoload: false, 
      autoLoad : false, 
      proxy: { 
       type: 'ajax', 
       url: 'data.php', 
       reader: { 
        type: 'json', 
        root: 'results'     
       } 
      } 
      }); 
+0

ja po prostu go zmienić i uzyskać ten sam problem :( – freestyle

+0

można zapewnić treepanel konfigurację? – jeewiya

+0

plz zobaczyć moją zmienił – freestyle

0

można po prostu dodać dane użytkownika root do przechowywania jak postępować

var store = Ext.create('Ext.data.TreeStore', { 
      autoLoad : false, 
      root: { 
       text: 'Corporate Media', 
       id: '0', 
       expanded: true 
      } 
      proxy: { 
       type: 'ajax', 
       url: 'data.php', 
       reader: { 
        type: 'json', 
        root: 'results'     
       } 
      } 
      }); 
+0

że nie jeszcze działa :( – freestyle

+0

można utworzyć przykład na jsfiddle używając kodu. Ja to sprawdzić. – jeewiya

+0

ale za pomocą php i jsfiddle myślę, że nie mogę.) Używam extjs 4.2.1.883, będę edytować mój tytuł – freestyle

Powiązane problemy