"Data model" - fields defined externally to the Store

37 views
Skip to first unread message

Barry Moss

unread,
Dec 17, 2013, 1:44:08 PM12/17/13
to gl...@googlegroups.com
Hi,

I am trying to define fields external to the Store and from the forum know that "Conceptually, a 'data model' is just a normal view model with some properties/fields flagged for serialization and dirty tracking. " - this was very helpful.

However, I have my "Data model" as follows:-

glu.namespace('basic_form.models').pricesModel =  {

    fields
:[
           
{name: 'company', type: 'string' },
           
{name: 'price',      type: 'float'},
           
{name: 'change',     type: 'float'},
           
{name: 'pctChange',  type: 'float'},
           
{name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
           
]
};

and my ViewModel as follows:-

glu.defModel('basic_form.page3arrayMod', {

        prices
: {mtype: 'basic_form.models.pricesModel'},

        priceStore
: {
            mtype
: 'arraystore',

            model
: this.prices,
       
/*
            fields: [
                {name: 'company' },
                {name: 'price',      type: 'float'},
                {name: 'change',     type: 'float'},
                {name: 'pctChange',  type: 'float'},
                {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
            ],
        */

            autoLoad
: true,
            data
: [
               
['3m Co',                               71.72, 0.02,  0.03,  '9/1 12:00am'],
               
['Alcoa Inc',                           29.01, 0.42,  1.47,  '9/1 12:00am'],
               
['Altria Group Inc',                    83.81, 0.28,  0.34,  '9/1 12:00am'],
               
['American International Group, Inc.',  64.13, 0.31,  0.49,  '9/1 12:00am'],
               
['Verizon Communications',              35.57, 0.39,  1.11,  '9/1 12:00am'],
               
['Wal-Mart Stores, Inc.',               45.45, 0.73,  1.63,  '9/1 12:00am']
           
]
       
}
});

I can read the Array with the Fields defined in the Store (currently shown commented out) this works - - but when I try and access the external Data model I get a "Uncaught TypeError: Cannot read property 'prototype' of undefined" error.

Can anyone help please?

Barry






Ryan Smith

unread,
Dec 18, 2013, 11:55:26 AM12/18/13
to gl...@googlegroups.com
Hey Barry,

Sorry for the delayed response, I was busy traveling.  I believe the problem with what you are seeing is that the extjs store is expecting one of their Ext.data.Model objects to be in the model attribute of the store.  Granted, the model you have provided does define the fields properly, but I believe that the Ext.data.Model does some other "magic" to get things to work with the store.  There was once talk about having the glujs viewmodel extend the data.Model, but we weren't sure about conflicting with their code and decided to keep it separate.  If you want to define the model like you have done I would go with a normal Ext.data.Model and reference it there in the store instead of using an object definition like you are doing now.

Another point that might be causing the failure would be your reference to "this.prices" in the definition of the store.  You have to remember that when you are defining the properties of a viewmodel that you are really defining the "class".  What you have done is the equivalent in java of saying: private String temp = this.getSomething(); which isn't going to work because there isn't a reference to "this" at "compile time".  Once you have instantiated the object (during the init function of the viewmodel) then you can reference "this" correctly and get everything working no problem.

For most all of my stores though, I define the fields just like you have commented out.  I find that its easier to understand when the definition of the fields is right there where I'm doing work with grids.  I also define the columns in the viewmodel for that very reason.  So if I need to add a field/column to the grid, then I only have one file to modify and its easier to keep things straight (personal preference though, so you are free to discard all that :) ).

If you are still having problems, feel free to let me know and I can help you dig deeper into the problem you're having.  Have a great day!

-Ryan


--
You received this message because you are subscribed to the Google Groups "GluJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glujs+un...@googlegroups.com.
To post to this group, send email to gl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glujs/d60f56bd-c2c2-46f8-863f-5b9d9a8c6d38%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Barry Moss

unread,
Dec 18, 2013, 1:15:22 PM12/18/13
to gl...@googlegroups.com
Hi Ryan,

Thanks for your reply and support - it really is appreciated.  

Let me take a look in more detail at the points you make and try-out a couple of examples.

Regards,  ( for now  ! )


Barry

Ryan Smith

unread,
Dec 18, 2013, 1:17:54 PM12/18/13
to gl...@googlegroups.com
Sounds great Barry, good luck!

-Ryan


--
You received this message because you are subscribed to the Google Groups "GluJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glujs+un...@googlegroups.com.
To post to this group, send email to gl...@googlegroups.com.

murrayh...@gmail.com

unread,
Jun 28, 2015, 8:32:35 PM6/28/15
to gl...@googlegroups.com
Hi Barry,
This is off-topic but how do you get the code markup in your posts? I cant seem to find a way to do it?
Thanks,
Murray
Reply all
Reply to author
Forward
0 new messages