Looks like we can't reproduce the issue or there's a problem in the test case provided.
  1. #1
    Sencha Premium Member
    Join Date
    Dec 2011
    Posts
    13
    Vote Rating
    1
    DodgyDave is on a distinguished road

      0  

    Default [Beta 2] MVC, store and selectfield not populating

    [Beta 2] MVC, store and selectfield not populating


    I'm not sure if this is a bug or if I'm doing something fundamentally wrong but I cannot get a selectfield to populate from a store using a MVC styled app.

    This is a simple example to demonstrate the problem.

    app.js
    Code:
    Ext.Loader.setConfig({
    enabled:
    Code:
    true
    });
    Ext.application({
    name: 'test',
    useLoadMask: true,
    controllers: ['Main'],
    stores: ['ServiceType'],
    models: ['ServiceType'],
    views: ['Main'],
    launch: function() {
    }
    });
    



    model\ServiceType.js

    Code:
    Ext.define(
    Code:
    'test.model.ServiceType', {
    extend: 'Ext.data.Model',
    config: {
    fields: [
    { name: 'Code', type: 'string' },
    { name: 'Description', type: 'string' }
    ]
    }
    });
    
    store\ServiceType.js

    Code:
    
    Ext.define('test.store.ServiceType', {
    extend: 'Ext.data.Store',
    requires: ['test.model.ServiceType'],
    config: {
    model: 'test.model.ServiceType',
    storeId: 'Stevo',
    data: [{ Code: 'Test', Description: 'Test description' }, { Code: 'Test1', Description: 'Test1 description' }, { Code: 'Test2', Description: 'Test2 description'}]
    }
    });
    
    



    view/Main.js

    Code:
    Ext.define(
    Code:
    'test.view.Main', {
    
    extend: 'Ext.Container',
    requires: [
    'Ext.Container'
    
    ],
    config: {
    fullscreen: true,
    items: [{xtype:'selectfield',
    id: 'servicetype',
    config: {
    store: 'Stevo',
    valueField: 'Code',
    displayField: 'Description'
    
    }
    }
    ]
    }
    });
    
    controller/Main.js

    Code:
    Ext.define(
    Code:
    'test.controller.Main', {
    extend: 'Ext.app.Controller',
    init: function () {
    Ext.create('test.view.Main');
    },
    });
    


  2. #2
    Sencha - Sencha Touch Dev Team Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661
    Vote Rating
    21
    Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough

      0  

    Default


    We'll look into it.

    Sencha Inc

    Jamie Avins

    @jamieavins

  3. #3
    Sencha - Sencha Touch Dev Team rdougan's Avatar
    Join Date
    Oct 2008
    Posts
    1,158
    Vote Rating
    6
    rdougan will become famous soon enough

      0  

    Default


    Remove the storeId from your store. It is automatically generated from the className of your store. So your 'test.store.ServiceType' store would be available using 'ServiceType' (just like you define in your app.js):

    Code:
    {
        xtype: 'list',
        store: 'ServiceType',
        itemTpl: '{fieldName}'
    }
    Sencha Inc.
    Robert Dougan - @rdougan
    Sencha Touch 2 and Ext JS 4 Core Team Member, SASS/Theming Wizard.

  4. #4
    Sencha User aflx's Avatar
    Join Date
    Jun 2011
    Location
    Berlin, Germany
    Posts
    64
    Vote Rating
    0
    aflx is on a distinguished road

      0  

    Default


    @rdougan: That's not right! Maybe it should be so, but I debugged "sencha-touch-all-debug.js" and it isn't.
    If you don't add a storeId, there will be generated something like "my-package-storename-1". If you try to get the store by Ext.getStore('Storename'), this won't return a result, because in the manager there is no such id in the map (there you can only find the generated long version)!

    Alex

  5. #5
    Sencha - Sencha Touch Dev Team rdougan's Avatar
    Join Date
    Oct 2008
    Posts
    1,158
    Vote Rating
    6
    rdougan will become famous soon enough

      0  

    Default


    So I looked at your code again and it seems that the problem is that you are giving a 'config' block where you create your selectfield.

    config blocks are only used when you use Ext.define to create a new class. If you are creating an instance of a class which already exists (using Ext.create, or using a simple block object like you have with selectfield), you put the configuration options in the object itself.

    So your view code should look like this:

    Code:
    Ext.define('test.view.Main', {
        extend: 'Ext.Container',
        requires: [
            'Ext.Container'
        ],
        config: {
            fullscreen: true,
            items: [
                {
                    xtype:'selectfield',
                    id: 'servicetype',
                    store: 'ServiceType',
                    valueField: 'Code',
                    displayField: 'Description'
                }
            ]
        }
    });
    Sencha Inc.
    Robert Dougan - @rdougan
    Sencha Touch 2 and Ext JS 4 Core Team Member, SASS/Theming Wizard.

  6. #6
    Sencha Premium Member
    Join Date
    Dec 2011
    Posts
    13
    Vote Rating
    1
    DodgyDave is on a distinguished road

      0  

    Default


    Thanks, that has fixed the problem.