1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    71
    Vote Rating
    0
    arandlett is on a distinguished road

      0  

    Default How to pass data to store

    How to pass data to store


    I have a list view that calls a store for the list data. I am trying to pass data to the store for filtering or a different url for the proxy how would I accomplish this?

    List View:
    Code:
    Ext.define('MonkTouch.view.List', {
        extend : 'Ext.List',
        xtype  : 'mtouch-list',
        
        storeId:null,
        constructor : function(config) {
            this.setItemTpl(config.template);
            Ext.apply(config, {
                store : Ext.create('MonkTouch.store.Media')         
            });
            this.callParent([config]);
        }
    });
    Store:
    Code:
    Ext.define('MonkTouch.store.Media',{
        extend: 'Ext.data.Store',
        model: 'MonkTouch.model.Media',
        
        autoLoad: true,
        proxy:{
            type:'ajax',
            url:'/lib/mk-modules/media.php',
            reader:{
                type:'json',
                root:'items'
            }
        },
        remoteFilter:true,
        filters:[]
    });

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,330
    Vote Rating
    846
    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


    If you want to change the url, I would add a little logic to the store definition you made.

    Code:
    Ext.define('MonkTouch.store.Media', {
        extend: 'Ext.data.Store',
        model: 'MonkTouch.model.Media',
        
        autoLoad: true,
        remoteFilter:true,
        filters:[],
    
        constructor: function(config) {
            config.proxy = {
                type : 'ajax',
                url : config.url,
                reader : {
                    type : 'json',
                    root : 'items'
                }
            };
    
            delete config.url;
    
            this.callParent(config);
        }
    });
    Now you should be able to create a store like:

    Code:
    Ext.create('MonkTouch.store.Media', {
        url : '/lib/mk-modules/media.php'
    });
    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
    Jun 2011
    Posts
    71
    Vote Rating
    0
    arandlett is on a distinguished road

      0  

    Default


    why did you do config.proxy instead of this.proxy?

  4. #4
    Sencha User
    Join Date
    Jun 2011
    Posts
    71
    Vote Rating
    0
    arandlett is on a distinguished road

      0  

    Default


    Everytime I try to set config.proxy as you have above I get a JS error. The error just says "Error:".

Thread Participants: 1

Tags for this Thread