1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    15
    Vote Rating
    0
    matvey is on a distinguished road

      0  

    Default Answered: Model not being recognized

    Answered: Model not being recognized


    Hi,

    I'm new to Sencha and I'm trying to get started using Sencha 2.0 My sample application is very simple - it has three tabs at the top, and displays a list of hard-coded restaurants at the bottom. Sencha renders the list, and I can see three restaurants being added, but the Model for the restaurant that I defined appears to be ignored, and so the contents come out blank. There are no exceptions or warnings on the console.

    Here is the application for reference:

    Code:
    Ext.application({
        requires: [
            'Ext.tab.Panel',
        'Restaurants',
        'RestaurantModel'
        ],
    
    
        launch: function() {
            Ext.Viewport.add({
                xtype: 'tabpanel',
    
    
                items: [
                    {
                        xtype: 'restaurantList'
                    },
                    {
                        title: 'Map',
                        html: 'Map',
                        cls: 'card2'
                    },
                    {
                        title: 'Options',
                        html: 'Options',
                        cls: 'card3'
                    }
                ]
            });
        },
    });
    
    
    Ext.define('RestaurantModel', {
       extend: 'Ext.data.Model',
       fields: ['rname', 'address']
    });
    
    
    var myStore = Ext.create('Ext.data.Store', {
        model: 'RestaurantModel',
        sorters: 'rname',
    
    
        data: [
            {rname: 'Lezzette',      address: '460 W 34th St'},
            {rname: 'Thai Select',   address: '200 9th Ave'},
            {rname: 'Thai Select',   address: '200 9th Ave'}
        ]    
    });
    
    
    Ext.define('Restaurants', {
        extend: 'Ext.List',
        xtype: 'restaurantList',
    
    
        config: {
        title: 'List',
        store: myStore,
        itemTpl: [
            '<div>Name: {rname} Address: <strong>{address}</strong></div>',
        ].join('')
        }
    });
    I've been banging my head against this for the past two days. Please help!

    Thanks!
    -Matt

  2. You should not use Ext.create before the launch method is fired.

  3. #2
    Sencha User
    Join Date
    Feb 2012
    Posts
    37
    Answers
    3
    Vote Rating
    0
    shivbhaw is on a distinguished road

      0  

    Default


    which version of sencha are you using, because in the newer versions ive noticed that you must put alot of the data for the store into the config..thus making your store like this(I am not too sure if this will work, but i believe it should, thats how i have it when i define it):

    Code:
    var myStore = Ext.create('Ext.data.Store',
    {
        config:{
             model: 'RestaurantModel',
            sorters: 'rname',
             data: [
                {rname: 'Lezzette',     address: '460 W 34th St'},
                {rname: 'Thai Select',   address: '200 9th Ave'},
                {rname: 'Thai Select',   address: '200 9th Ave'}
             ]
        }
    });

  4. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    37
    Answers
    3
    Vote Rating
    0
    shivbhaw is on a distinguished road

      0  

    Default


    also i believe its the same thing with the Model, so the fields from there goes inside the config: {}

  5. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,207
    Answers
    3517
    Vote Rating
    858
    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


    Yes, any config needs to go within the config object when using Ext.define.
    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.

  6. #5
    Sencha User
    Join Date
    Feb 2012
    Posts
    15
    Vote Rating
    0
    matvey is on a distinguished road

      0  

    Default


    Thanks for getting back to me so quickly. I tried throwing "config" around both the Model and the Store, but it didn't help. The behavior remained exactly the same.

    I'm using Sencha 2, Beta 3 (latest one).

  7. #6
    Sencha User
    Join Date
    Feb 2012
    Posts
    15
    Vote Rating
    0
    matvey is on a distinguished road

      0  

    Default


    Amazingly, not even this simple example, that came directly from the List API page, works for me.

    Code:
    Ext.define('RestaurantModel', {
       extend: 'Ext.data.Model',
       config: {
       	fields: ['rname', 'address']
       }
    });
    
    
    var store = Ext.create('Ext.data.Store', {
       model: 'RestaurantModel',
       sorters: 'rname',
    
    
    	data: [
    		{rname: 'Lezzette',      address: '460 W 34th St'},
    		{rname: 'Thai Select',   address: '200 9th Ave'},
    		{rname: 'Thai Select',   address: '200 9th Ave'}
    	]
    });
    
    
    var list = Ext.create('Ext.List', {
       itemTpl: '<div>Name: {rname} Address: <strong>{address}</strong></div>',
       store: store,
       fullscreen: true
    });
    
    
    Ext.application({
        launch: function() {
            Ext.Viewport.add(list);
        },
    });
    This one is rendered correctly in Chrome, but not on my phone (Droid Incredible).

  8. #7
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,207
    Answers
    3517
    Vote Rating
    858
    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


    You should not use Ext.create before the launch method is fired.
    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.

  9. #8
    Sencha User
    Join Date
    Feb 2012
    Posts
    15
    Vote Rating
    0
    matvey is on a distinguished road

      0  

    Default


    Mitchell, thanks for your help! That was it, it's working now. Rookie mistake on my part.

Thread Participants: 2