1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    4
    Vote Rating
    0
    Sageo is on a distinguished road

      0  

    Default Unanswered: Data Store

    Unanswered: Data Store


    Hey..

    I just started developing with sencha touch.
    I have a small problem while working with Store..I am not able to get data as i need.Its a simple data.
    Below is how i create the store..


    Ext.regModel('Alert', {
    fields: [
    'AlertType', 'AlertName','AlertDescription']

    });
    Ext.AlertData = new Ext.data.Store({
    id:'AlertStoreId',
    model:'Alert',
    sorters: [{
    property: 'AlertType'
    }],

    autoLoad : true,
    proxy:{
    type:'ajax',
    url:'my url is here.',
    reader:{
    type:'xml',
    record:'Alert'
    }
    }


    }
    );
    What i want is all the values for 'AlertType' field in an array.
    Please post complete implementation(code).Because i have tried many things like getGroupedString..and Filters, setting grouped property etc...etc..Nothing seems to work.

    My store is populated properly with data...

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,525
    Vote Rating
    871
    Answers
    3564
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    For Sencha Touch 2, you should define your Model and create your store this way:

    Code:
    Ext.define('Alert', {
        extend : 'Ext.data.Model',
        fields: ['AlertType', 'AlertName','AlertDescription']
    });
    
    Ext.AlertData = Ext.create('Ext.data.Store', {
        model:'Alert',
        sorters: [{
            property: 'AlertType'
        }],
    
        autoLoad : true, 
        proxy:{
            type:'ajax',
            url:'my url is here.',
            reader:{
                type:'xml', 
                record:'Alert'
            }
        }
    });
    For your Store, I wouldn't use the Ext namespace. You should have one for your namespace. You can go through your Store using the each method:

    Code:
    var values = [];
    store.each(function(rec) {
        values.push(rec.get('AlertType'));
    });
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Nov 2011
    Posts
    4
    Vote Rating
    0
    Sageo is on a distinguished road

      0  

    Default


    The snippet does not seem to work.I am still getting an empty array.

    Below is not working
    var values = [];
    Ext.AlertData.each(function(rec) {
    values.push(rec.get('AlertType'));
    console.log(rec.get('AlertType'));
    });
    console.log("values",values);

    Below is not working
    var values = [];
    Ext.AlertData.on('load', function () {
    Ext.AlertData.data.each(function(rec) {
    values.push(rec.get('AlertType'));
    })});
    console.log("values",values);

    Below is working: The data gets printed in the console.
    Ext.AlertData.on('load', function () {
    Ext.AlertData.data.each(function(rec) {
    console.log(rec.get('AlertType'));
    })});

    Please provide a solution..

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,525
    Vote Rating
    871
    Answers
    3564
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    This is working for me 100%:

    Code:
        var store = Ext.create('Ext.data.ArrayStore', {
            fields: [
               {name: 'company'},
               {name: 'price',      type: 'float'},
               {name: 'change',     type: 'float'},
               {name: 'pctChange',  type: 'float'},
               {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
            ],
            proxy : {
                type   : 'ajax',
                url    : 'data.php',
                reader : {
                    type : 'json',
                    root : 'data'
                }
            }
        });
    
        var values = [];
        store.on('load', function() {
            store.each(function(rec) {
                values.push(rec.get('company'));
            });
    
            console.log(values); //is an array with all companies
        });
    
        store.load();
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Sencha User
    Join Date
    Nov 2011
    Posts
    4
    Vote Rating
    0
    Sageo is on a distinguished road

      0  

    Default Hi..

    Hi..


    Is this happening because I am doing an HTTP connection and the retrieving the data from a URL..Issue of asynchronous call?

  6. #6
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,525
    Vote Rating
    871
    Answers
    3564
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Quote Originally Posted by Sageo View Post
    Is this happening because I am doing an HTTP connection and the retrieving the data from a URL..Issue of asynchronous call?
    You will need to do it after things have been loaded
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  7. #7
    Sencha User
    Join Date
    Nov 2011
    Posts
    4
    Vote Rating
    0
    Sageo is on a distinguished road

      0  

    Default


    But how do I know that..when it has loaded...

  8. #8
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,525
    Vote Rating
    871
    Answers
    3564
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Code:
    store.load({
        callback: function(records, operation, success) {
            //store has been loaded
        }
    });
    or

    Code:
    store.on('load', function(store, recs, success) {
        //store has been loaded, single : true will remove this listener after first time executing
    }, store, { single : true });
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1

Tags for this Thread