Results 1 to 4 of 4

Thread: How to pass data to store

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    71
    Vote Rating
    0
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,551
    Vote Rating
    1271
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Jun 2011
    Posts
    71
    Vote Rating
    0
      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
      0  

    Default

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

Tags for this Thread

Posting Permissions

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