1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    16
    Vote Rating
    0
    FullThrottle is on a distinguished road

      0  

    Default Assigning store to list MVC Pattern

    Assigning store to list MVC Pattern


    I'm having some trouble assigning a store to a list. I can do it dynamically in the controller, but I can not seem to get the store property of the list itself to work.

    Controller:
    Code:
    Ext.define('Test.controller.PatientController', {
        extend: 'Ext.app.Controller',
    
    
        config: {
            profile: Ext.os.deviceType.toLowerCase()
        },
    
    
        views: [
            'PatientList'
        ],
        stores: [
            'PatientStore'
        ],
        models: [
            'PatientModel'
        ],
    
    
        init: function()
        {
            Ext.getCmp('patientList').setStore('PatientStore');
        }
    });
    Store:
    Code:
    Ext.define('Test.store.PatientStore', {
        extend: 'Ext.data.Store',
        model: 'Test.model.PatientModel',
        requires: [ 'Test.model.PatientModel' ],
        storeId: 'patientStore',
        sorters: 'lastName',
        getGroupString: function(record){
            return record.get('lastName')[0];    
        },
        autoLoad: false,
        autoSync: true,
    
    
        proxy: {
            type: 'ajax',
            api: {
                read: '../Services/PatientWebService.asmx/GetAllPatients'
            },
            reader: {
                type: 'xml',
                record: 'PatientData',
                root: 'ArrayOfPatientData'
            },
            afterRequest: function(response, opts){
    
    
            }
        }
    });
    List:

    Code:
    Ext.define('Test.view.PatientList', {
        extend: 'Ext.dataview.List',
        xtype: 'patientList',
        id: 'patientList',
        fullscreen: true,
        config: {
            itemTpl: '<div id="{id}">{lastName}, {firstName}</div>',
            listeners: {
                scope: this,
                itemtap: this.onItemTap
            }
        },
    
    
        onItemTap: function(record, newItem){
            if(newItem.attributes['id'] != undefined)
            {
                Ext.getCmp('mainPanel').setActiveItem(2);
                Ext.data.StoreManager.lookup('PatientDateStore').getProxy().extraParams.ID = newItem.attributes['id'].value;
                Ext.data.StoreManager.lookup('PatientDateStore').load();
            }
            else if (newItem.childNodes[0].attributes['id'] != undefined)
            {
                Ext.getCmp('mainPanel').setActiveItem(2);
                Ext.data.StoreManager.lookup('PatientDateStore').getProxy().extraParams.ID = newItem.childNodes[0].attributes['id'].value;
                Ext.data.StoreManager.lookup('PatientDateStore').load();
            }
            else
            {
                Ext.Msg.alert('Error', 'Patient does not have a valid ID, please try again.')
            }
        }
    });
    If I put the storeId in the List's config section the data doesn't load, the only way I've seen data load is by setting it in the controller which I don't really like how that looks.

    What I add to the List config section:

    Code:
    store: 'PatientStore'

  2. #2
    Sencha User joejernst's Avatar
    Join Date
    Apr 2009
    Posts
    32
    Vote Rating
    0
    joejernst is on a distinguished road

      0  

    Default


    I had the same problem. The solution is in this thread: http://www.sencha.com/forum/showthre...ng-MVC-pattern

  3. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    16
    Vote Rating
    0
    FullThrottle is on a distinguished road

      0  

    Default


    Awesome, that totally fixed it. I thought including the store in the controller would do what the stores property in the app.js does, but apparently not. Thx

Thread Participants: 1