1. #1
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    108
    Answers
    4
    Vote Rating
    1
    paulh1971 is on a distinguished road

      0  

    Default Unanswered: View with text from a database

    Unanswered: View with text from a database


    Hello, I have a view that has text, but I want the text to be pulled from a database using JsonP instead of being hard-coded. I have the JsonP file created, the store and model setup, but am not sure how to get the data to the view. I have not had a problem with doing this type of thing with a data list, but not sure how to without a data list.

    This seems like it would be pretty straight forward and easy, but I can't seem to figure it out.

    Any help would be so greatly appreciated.

    Thanks,
    Paul

  2. #2
    Sencha User jerome76's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,149
    Answers
    132
    Vote Rating
    99
    jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice

      0  

    Default


    Let's just say we have this code, from Ext.data.proxy.JsonP
    Code:
    Ext.define('User',{ 
        extend: 'Ext.data.Model', 
        config:{ 
            fields:['id', 'name', 'email']
        }
    });
    
    var store = Ext.create('Ext.data.Store', { 
        model: 'User', 
        proxy:{ 
            type: 'jsonp',
            url : 'http://domainB.com/users'
        }
    });
    Now depending on how your json looks like, you can retrieve the data and the set it as the html in your panel.
    Code:
    //example html.json file stored in the folder 'data'
    [
        {
            html: '... html content here ...'
        }
    ]
    Code:
    Ext.define('html',{ 
        extend: 'Ext.data.Model', 
        config:{ 
            fields:['html']
        }
    });
    
    var store = Ext.create('Ext.data.Store', { 
        model: 'html', 
        proxy:{ 
            type: 'jsonp',
            url : '../data/html.json' //you can use a local url here like so
        },
        listeners: {
            load: function(store, records){
               ... //get the view, assuming it is a Panel below
               (view).setHtml(records[0].get('html'));
            }
        }
    });
    I hope this helps you out.

Thread Participants: 1

Tags for this Thread