Results 1 to 5 of 5

Thread: me.model is undefined

  1. #1
    Sencha User
    Join Date
    Jul 2009
    Location
    The Netherlands
    Posts
    196

    Default me.model is undefined

    Hi,

    I'm doing currently the MVC guide, and at some point it goes wrong, the moment the model is created and used for the store. This code is from the guide:

    Model:
    Code:
    Ext.define('AM.model.User', 
    {     
        extend: 'Ext.data.Model',
        fields: ['name', 'email']
    });
    Controller update:
    Code:
    //the Users controller will make sure that the User model is included on the page and available to our app 
    
    Ext.define('AM.controller.Users', 
    {     
        extend: 'Ext.app.Controller',
        stores: ['Users'],
        models: ['User'],
        ... 
    });
    Store update:
    Code:
    // we now reference the Model instead of defining fields inline Ext.define('AM.store.Users', 
    {
        extend: 'Ext.data.Store',
        model: 'User',
        data: [
        {
            name: 'Ed',
            email: '[email protected]'
        },
        {
            name: 'Tommy',
            email: '[email protected]'
        }] 
    });
    However, when i try this, i get the following error: me.model is undefined.

    I looked at the 'app - simple' mvc example, and they used this code for the store:

    Code:
    Ext.define('AM.store.Users', 
    {
        extend: 'Ext.data.Store',
        model: 'AM.model.User',
        data: [
        {
            name: 'Ed',
            email: '[email protected]'
        },
        {
            name: 'Tommy', 
            email: '[email protected]'
        }] 
    });
    So 'AM.model.User' is used instead of 'User'. I tried this, and it worked. However, i wondered why only 'User' won't work? I thought that if the controller 'adds' the User model, it creates automatically an id for it?

    For example, the store itself is also used in the List.js file (a view) like:

    Code:
    store: 'Users'
    ... and that works just fine (because the controller creates an id for it), but how i look at it, this won't do for the model.

    A bug?

  2. #2
    Sencha User
    Join Date
    Apr 2011
    Posts
    3

    Default

    I thought about the exact same thing. It looks like it should not need the absolute "path" to it.

  3. #3
    Ext JS Premium Member
    Join Date
    Apr 2011
    Location
    Dallas, TX
    Posts
    204

    Default

    In the store, you must assign the Model as follows:

    Code:
    model: 'AM.model.User',
    See this post as well about the MVC Application Architecture guide.

  4. #4
    Sencha Premium Member steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,675

    Default

    to answer the question, why
    Code:
    model: 'User'
    don't work:

    The store has no shortcuts to the paths and namespace, so you always have to use the complete namespace.

    It's different to the controller. There you have
    Code:
    models: ['User']
    The controller knows about the app path and asks Loader to load User.js from model directory.
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  5. #5
    Sencha User
    Join Date
    Dec 2011
    Posts
    22

    Default

    I was seeing a similar issue until on my store I specified the model in the "requires:[...]". For example:
    Code:
    Ext.define('Vio.store.UserStore', {
        extend: 'Ext.data.Store',
        requires: ['Vio.model.UserDataModel'],
        constructor: function(cfg) {
            var me = this;
            cfg = cfg || {};
            me.callParent([Ext.apply({
                
                pageSize: 10,
                model: 'Vio.model.UserDataModel'
                
            }, cfg)]);
        }
    });

Similar Threads

  1. Replies: 1
    Last Post: 16 Mar 2011, 10:40 PM
  2. [FIXED]Model root is undefined error
    By sg707 in forum Ext:Bugs
    Replies: 7
    Last Post: 15 Mar 2011, 5:14 AM
  3. Replies: 0
    Last Post: 17 Feb 2011, 5:21 PM
  4. [FIXED-187] The model data become undefined.
    By taka_2 in forum Sencha Touch 1.x: Bugs
    Replies: 5
    Last Post: 14 Aug 2010, 5:18 AM
  5. Replies: 2
    Last Post: 17 Jun 2010, 6:53 AM

Posting Permissions

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