Hybrid View

  1. #1
    Sencha User
    Join Date
    Aug 2012
    Posts
    2
    Vote Rating
    0
    kuarama1990 is on a distinguished road

      0  

    Default Unanswered: Cannot read second value in nested json file

    Unanswered: Cannot read second value in nested json file


    For easier to understand I will show my currently code first

    My Json:

    Code:
    {
        "success": true,
        "message": "Request retrieved with id:789",
        "data": {
            "id": 789,
            "description": "request description",
            "subject": "request subject",
            "progresses": [
                {
                    "description": "progress description 1"
                },
                {
                    "description": "progress description 2"
                },
                {
                    "description": "progress description 3"
                }
            ]
        }
    }
    My store:

    Code:
    Ext.define('KitchenSink.store.RequestStore', {
        extend: 'Ext.data.Store',
    
    
        config: {
            autoLoad: true,
            //autoSync: true,
            model: 'KitchenSink.model.RequestModel'
        }
    });
    My Request Model:

    Code:
    Ext.define('KitchenSink.model.RequestModel', {
        extend: 'Ext.data.Model',
        
        requires: [
            'KitchenSink.model.ProgressModel'
        ],
        
        config: {
            fields: [
                {
                    name: 'id'
                },
                {
                    name: 'description'
                },
                {
                    name: 'subject'
                }
            ],
            hasMany: {
                associationName: 'progresses',
                associationKey: 'progresses',
                model: 'KitchenSink.model.ProgressModel'
            },
            proxy: {
                type: 'ajax',
                url: 'progress.json',
                reader: {
                    type: 'json',
                    rootProperty: 'data'
                }
            }
        }
    });
    My Progress Model:

    Code:
    Ext.define('KitchenSink.model.ProgressModel', {
        extend: 'Ext.data.Model',
        
        config: {
            fields: [
                {
                    name: 'description'
                }
            ],
            belongsTo: {
                model: 'KitchenSink.model.RequestModel'
            }
        }
    });
    This is my view:

    Code:
    Ext.define('KitchenSink.view.example27', {
        extend: 'Ext.dataview.DataView',
        xtype: 'example27',
        
        config: {
            title: 'Example 27',
            iconCls: 'bulb',        
            
            store: 'RequestStore',
            itemTpl: [
            '<div>',
            '   <div>ID</div>',
            '   <div>{id}</div>',
            '           ',
            '   <div>Subject</div>',
            '   <div>{subject}</div>',
            '           ',
            '   <div>Description</div>',
            '   <div>{description}</div>',
            '</div>',
            '',
            '<h2><b>Progress:</b></h2>',
            '<tpl for="progressmodels">',
            '    <div>',
            '        <div>{description}</div>',
            '    </div>',
            '</tpl>'
            ].join('')
        }
    });
    My Question:

    Currently I can show the
    id,description and subject but In case of the progress, I want all
    progressdescription to be shown, but only the first description is displayed now. Am I missing something? Can any one help me to figure it out because I stuck at this problem for a few days already. Any help would be greatly appreciated!

  2. #2
    Sencha - Community Support Team sword-it's Avatar
    Join Date
    May 2012
    Location
    Istanbul
    Posts
    1,333
    Answers
    124
    Vote Rating
    85
    sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough

      0  

    Default


    Hi kuarama1990,
    I think you should make some changes in you tpl. Review the following code:

    Code:
     '<tpl for="progresses">',    
       // progresses will be the field name that you have added in RequestModel
         '<div>',
            '<div>{description}</div>',
         '</div>',
     '</tpl>'
    Last edited by sword-it; 4 Oct 2012 at 7:12 AM. Reason: setting code formatting
    sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.

  3. #3
    Sencha User
    Join Date
    Aug 2012
    Posts
    2
    Vote Rating
    0
    kuarama1990 is on a distinguished road

      0  

    Default


    Hi sword-it:

    Thank you for your answer but I have already tried it and this time is even worse when the result is not even display the first description.

Thread Participants: 1

Tags for this Thread