Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: no data in panel

  1. #1
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    48

    Default Answered: no data in panel

    hello
    i'm new to Extjs
    i have a problem




    1. my json
    {"root":
    "success":"false"
    "items":[
    {
    "type":"Error",
    "title":"Title",
    "message":"Message",
    "key":""
    },
    {
    "type":"Error",
    "title":"Title",
    "message":"Message",
    "key":""
    }
    ]}

    2.store

    var project_val = Ext.create('Ext.data.ArrayStore', {
    model: 'project_val',
    autoLoad : true
    });



    3.model

    Ext.define('project_val',{
    extend:'Ext.data.Model',
    fields:[
    {name:'success',type:'string'},
    {name:'type',type:'string',mapping:'items.type'},
    {name:'title',type:'string',mapping:'items.title'},
    {name:'message',type:'string',mapping:'items.message'},
    {name:'key',type:'string',mapping:'items.key'}
    ],
    hasOne: {model:'items',name:'items'},
    proxy:{
    type: 'ajax',
    url:'resource/json/result.json',
    reader:{
    type:'json',
    root:'root'
    }
    }
    });

    Ext.define('items',{
    extend:'Ext.data.Model',
    fields:[
    {name:'type',mapping:'record[0].type'},
    {name:'title',mapping:'record[1].title'},
    {name:'message',mapping:'record[2].message'},
    {name:'key',mapping:'record[3].key'}
    ],
    belongTo:'project_val'
    });



    4. view

    //xtemplate
    var temp = new Ext.Template(
    '<div>hello</div>'
    );

    // panel

    var valPanel = Ext.create('Ext.panel.Panel',{
    store:project_val,
    title:'Your dataset show below error',
    id:'gridVal',
    tpl:temp
    });

  2. Try this:
    Code:
        var project_val = Ext.create('Ext.data.Store', {
            model: 'project_val',
            autoLoad : true,
            listeners: {
                load: function(){
                    console.log(project_val, project_val.getAt(0).items());
    
    
                    var valPanel = Ext.create('Ext.panel.Panel',{
                        renderTo: Ext.getBody(),
                        width: 400,
                        height: 200,
                        data: project_val,
                        title:'Your dataset show below error',
                        id:'gridVal',
                        tpl: new Ext.XTemplate(
                            '<tpl for=".">',
                                '<div><b>Title:</b> {data.success}</div>', 
                                '<div><b>Message:</b><ul>',
                                    '<tpl for="items()">',
                                        '<li>{data.type} - {data.title} - {data.message} - {data.key}</li>',
                                    '</tpl>',
                                '</ul></div>',
                            '</tpl>'
                        )
                    });
                }
            }
        });

  3. #2
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    48

    Default the problem is

    i see panel on window
    but no data displayed.

    help me please

  4. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    347

    Default

    Firstly, your Json data is incorrect. So you should check it again.

  5. #4
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    48

    Default i fixed my json

    {
    "root": [{
    "success": "false",
    "items": [{
    "type": "error",
    "title":"Title",
    "message":"Message",
    "key":"this data error"
    },{
    "type":"Error",
    "title":"Title",
    "message":"Message",
    "key":"019 error"
    }]
    }]
    }

  6. #5
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    48

    Default and i fixed my model

    Ext.define('items',{
    extend:'Ext.data.Model',
    fields:[
    {name:'type',type:'string'},
    {name:'title',type:'string'},
    {name:'message',type:'string'},
    {name:'key',type:'string'}
    ],
    belongTo:'project_val'
    });

  7. #6
    Sencha User
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    347

    Default

    According to your new json data and items model. You should fix project_val model as below:
    Code:
    Ext.define('project_val',{
        extend:'Ext.data.Model',
        fields:[
            {name:'success',type:'string'},
    //      {name:'type',type:'string',mapping:'items.type'},
    //      {name:'title',type:'string',mapping:'items.title'},
    //      {name:'message',type:'string',mapping:'items.message'},
    //      {name:'key',type:'string',mapping:'items.key'}
        ],
    //  hasOne: {model:'items',name:'items'},
        hasMany: {model:'items',name:'items'},
        proxy:{
            type: 'ajax',
            url:'resource/json/result.json',
            reader:{
                type:'json',
                root:'root'
            }
        }
    });
    4. view
    //xtemplate
    var temp = new Ext.Template(
    '<div>hello</div>'
    );

    // panel

    var valPanel = Ext.create('Ext.panel.Panel',{
    store:project_val,
    title:'Your dataset show below error',
    id:'gridVal',
    tpl:temp
    });
    What do you want to do with this code?

  8. #7
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    48

    Default show error message

    thankyou for your help!
    and..

    I want to show error message
    this is just test.

    if success==false
    i want to show error

    else have nothing to do.

  9. #8
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    48

    Default thanx...

    But in store there is no data.

    when i use below

    Ext.define('project_val',{
    extend:'Ext.data.Model',
    fields:[
    {name:'success',type:'string'}
    {name:'type',type:'string',mapping:'items.type'},
    {name:'title',type:'string',mapping:'items.title'},
    {name:'message',type:'string',mapping:'items.message'},
    {name:'key',type:'string',mapping:'items.key'}
    ],
    hasMany: {model:'items',name:'items'},

    });

    Ext.define('items',{
    extend:'Ext.data.Model',
    fields:[
    {name:'type',type:'string'},
    {name:'title',type:'string'},
    {name:'message',type:'string'},
    {name:'key',type:'string'}
    ],
    belongTo:'project_val'
    });


    store has data.
    but value of type,title, message,key is just ''.

    do you have any solution??

  10. #9
    Sencha User
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    347

    Default

    Below is your code that I have up to now. Running this code and you will see project_val store will contain one record {"success": "false"}. You can access its items thru <record>.items(). This will return a store that contains all items of the record.
    Code:
    Ext.onReady(function(){
        Ext.define('project_val',{
            extend:'Ext.data.Model',
            fields:[
                {name:'success',type:'string'}
            ],
            hasMany: {model:'items',name:'items'},
            proxy:{
                type: 'ajax',
                url:'index.json',
                reader:{
                    type:'json',
                    root:'root'
                }
            }
        });
    
    
        Ext.define('items',{
            extend:'Ext.data.Model',
            fields:[
                {name:'type',type:'string'},
                {name:'title',type:'string'},
                {name:'message',type:'string'},
                {name:'key',type:'string'}
            ],
            belongTo:'project_val'
        });
    
    
        var project_val = Ext.create('Ext.data.Store', {  // use Store instead of ArrayStore
            model: 'project_val',
            autoLoad : true
        });
    
    
        console.log(project_val);
    });
    index.json
    Code:
    {
        "root": [{
            "success": "false",
            "items": [{
                "type": "error",
                "title":"Title",
                "message":"Message",
                "key":"this data error"
            },{
                "type":"Error",
                "title":"Title",
                "message":"Message",
                "key":"019 error"
            }]
        }]
    }

  11. #10
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    48

    Default thankyou very much.

    Thankyou very much.

    very helpful!!

    and i show some data in my panel.
    but still other data in items is not showed in my panel
    please look my panel please,

    my panel

    var valPanel = Ext.create('Ext.panel.Panel',{
    data:project_val,
    title:'Your dataset show below error',
    id:'gridVal',
    tpl:new Ext.XTemplate(
    '<tpl for=".">',
    '<div><b>Title:</b> {data.success}</div>',
    '<div><b>Message:</b> {data.items()}<div>',
    '</tpl>'),
    });

    data.success show its data 'false',
    but data in items is not showed.

    Do you have idea about this??

    thanx

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •