1. #1
    Ext JS Premium Member
    Join Date
    Dec 2011
    Posts
    203
    Vote Rating
    0
    nicolabaldo is on a distinguished road

      0  

    Default nested json with TreeStore

    nested json with TreeStore


    I use ExtJS 4.1.3 an Architect.

    This is my JSON:

    {"success":true,"message":"Ricerca eseguita con successo","data":[{"text":"1) PIA CASA","expanded":false,"leaf":false,"iconCls":"ICON_D","children":[{"text":"1) REP.TULIPANO","expanded":false,"leaf":false,"iconCls":"ICON_D","children":[{"text":"1) spese del personale","expanded":false,"leaf":false,"iconCls":"ICON_D","children":[{"text":"1) direzione generale","expanded":false,"leaf":true,"iconCls":"ICON_D","children":null,"cdaCode":"01-01-01-01","cda1":null,"cda2":null,"cda3":null,"cda4":1},{"text":"3) ragioneria","expanded":false,"leaf":true,"iconCls":"ICON_D","children":null,"cdaCode":"01-01-01-03","cda1":null,"cda2":null,"cda3":null,"cda4":3}]}

    Code:
    Ext.define('myModel', {
        extend: 'Ext.data.Model',
        fields: [
        {name: 'text'},
        {name: 'expanded'},
        {name: 'leaf'},
        {name: 'iconCls'},
        {name: 'children'},
        {name: 'cdaCode'},
        {name: 'cda1'},        
        {name: 'cda2'},        
        {name: 'cda3'},        
        {name: 'cda4'}        
        ]
    });     
    
    Ext.create('Ext.data.TreeStore', {
    		model: myModel,
    		proxy: {
    			type: 'ajax',
    			api: MyApi,
    			url: MyUrl,
    			reader: {
    				type: 'json',
    				idProperty: '',
    				messageProperty: 'message',
    				root: 'data'
    			}	
    		}	
    	});
    When I load the store I see the tree, but when I click on the first item ("PIA CASA") I don't see its children but the tree is reloaded...

    Immagine.png

  2. #2
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    8,185
    Vote Rating
    63
    aconran is just really nice aconran is just really nice aconran is just really nice aconran is just really nice aconran is just really nice

      0  

    Default


    You are using different root's at the top level you are using the root of "data" and at children level you are using the root of "children".

    Make these the same.
    http://docs.sencha.com/ext-js/4-1/#!...data.TreeStore

    Quote from linked docs "Reading Nested Data"
    For the tree to read nested data, the Ext.data.reader.Reader must be configured with a root property, so the reader can find nested data for each node (if a root is not specified, it will default to 'children'). This will tell the tree to look for any nested tree nodes by the same keyword, i.e., 'children'. If a root is specified in the config make sure that any nested nodes with children have the same name. Note that setting defaultRootProperty accomplishes the same thing.
    Aaron Conran
    @aconran
    Sencha Architect Development Team

  3. #3
    Ext JS Premium Member
    Join Date
    Dec 2011
    Posts
    203
    Vote Rating
    0
    nicolabaldo is on a distinguished road

      0  

    Default


    Ok thanks.