View Full Version : How to get Model's Field value

24 Jan 2011, 5:54 AM
Hi all,
I have Loaded a store with Model 'User'. After loading, how can i get model's field values?

Thanks in advance.

24 Jan 2011, 6:44 AM
i m also trying this
var model = Ext.ModelMgr.getModel(ModelName);console.log(model) shows me some thing like this function (){ superclass.apply(this, arguments); } instead of model object :( , is this a right way to get model object?

24 Jan 2011, 7:20 AM
Check out the Docs and read what each item does especially the 'get' method.

24 Jan 2011, 7:26 AM
thanks mitchell for your quick response
getModel returns the Ext.data.Model for a given model name but i am getting this function (){ superclass.apply(this, arguments); } when i call getModel function with model name as an argument. where mitchell do you think i am doing wrong?

24 Jan 2011, 7:37 AM
Just doing sudo code...


You only have to worry when you get 'undefined' and 'null' for the most part.

24 Jan 2011, 7:40 AM
thanks i tried this before but i get Uncaught TypeError: Object function (){ superclass.apply(this, arguments); } has no method 'get', i am not sure where i am doing wrong :(

24 Jan 2011, 7:42 AM
Are you doing this in an event of something or just by itself somewhere in the JS code?

24 Jan 2011, 7:44 AM
i am doing this in an event the code is like this

// loading store
var itemStore = Ext.StoreMgr.get('ItemStore');
// defining list items
var list = new Ext.List({
fullscreen: true,
itemTpl : [
'<div class="roundedBorder">',
'<div class="homeList">',
'<div class="{logoCls} fltL">{module}</div>',
'<div class="arrowRt fltR"></div>',

'<div class="pl10 homeMainListDesc">{description}</div>',
singleSelect: true,
allowDeselect: false,
indexBar: true,
store: itemStore,
listeners: {
itemtap: function (view, index, item, e){
var rec = view.store.getAt(index);
if(rec.get('module') == 'Food'){
}else if(rec.get('module') == 'Supplement'){
cls: 'homeMainList',
selectedItemCls: 'selectedListItem'
// rendering view
Application.views.home = Ext.extend(Ext.Panel, {
fullscreen: true,
layout: 'card',
items: [list]

// defining nutrition functionality and init the nutrition store
var loadNutrition = function(){

24 Jan 2011, 7:48 AM
Where is the User Model defined? Was it loaded?

Just a quick tip, in the itemtap listener for the List, instead of doing "rec.get('module')" twice, do something like:

var module = rec.get('module');
if (module === "Food") {
} else if (module === "supplement") {

24 Jan 2011, 8:02 AM
Thanks once again for your useful tip and reply.
Here is User Model.

Model.User = Ext.regModel('User', {
idProperty: 'UserModel',
'id', 'name'

Now i m loading User model like this:

var loadNutrition = function(){

and above console.log give me following error
Object function (){ superclass.apply(this, arguments); } has no method 'get'

is this right approach?

24 Jan 2011, 8:27 AM
Take a look at the docs http://dev.sencha.com/deploy/touch/docs/?class=Ext.data.Model

Here is how you should load a Model:

//get a reference to the User model class
var User = Ext.ModelMgr.getModel('User');

//Uses the configured RestProxy to make a GET request to /users/123
User.load(123, {
success: function(user) {
console.log(user.getId()); //logs 123

So in the success function, you can do user.get("fieldname")

24 Jan 2011, 8:51 AM
Mitchell i already populated my model and do not want to make a request to server, my concern is that when a model is initialized once is there any way to get model object so that i can use its getter and setter functions to get values, as far as documentation is concerned there is a function getModel(modelname) but i do not know why it is not returning me the model object instead of function (){ superclass.apply(this, arguments); } why this function is returning me with this string, i am too much confused :(

24 Jan 2011, 8:54 AM
Ok... so when you load, create a reference to that returned model...

success: function(user) {
this.userModel = user;

Now it is "attache" to whatever "this" is scoped to. Down the line you can use the get method.

24 Jan 2011, 9:19 AM
thanks Mitchell for your precious time and its very helpful for me, i have a question for you which i think can put me out of this problem , i have a user model and i used it in Store which makes a request to a server and loads the store, when doing this the models get loaded as well ? if not then how could i load both Store and model in a single ajax request.

Again thanks for your help :)

24 Jan 2011, 9:22 AM
So you are using a Store? Well that's different.

To get a model instance, you need to find the model within the Store. You can use many things on the Store: findBy, findExact, find, findRecord, getAt, getById. Docs are good at examples for those.

However, if you are only loading 1 Model, use a Model with a Proxy. Stores are used if you want to handle multiple Model instances.

24 Jan 2011, 9:31 AM
yahooooo :) thanks Mitchell i got it and its only because of your help, sorry i could't ask you very clearly about my problem.

24 Jan 2011, 9:33 AM
haha no problem :-)

1 Jun 2011, 6:30 AM

u can get values in models method like load.

var yourModel=Ext.ModelManager.getModel('wuu.model.yourModel');