PDA

View Full Version : record.get('string') returns undefined



sveatlo
25 Dec 2012, 9:48 AM
Hi,
I've got a following treestore:


Ext.define('Statistics.store.Menu', {
extend: 'Ext.data.TreeStore',
model: 'Menu',
storeId: 'MenuStore',
autoLoad: true,
autoSync: true,

proxy : {
type : 'ajax',
url : 'resources/scripts/get_menu.php?callback=1',
reader: {
type: 'json',
successProperty: 'success'
}
}


});


The get_menu.php script returns following JSON-formatted reply:



{"success": true,"children": [{"text": "Home","leaf": true},{
"text" : "Moje Firma s.r.o.",
"dbName" : "demo",
"leaf" : false,
"expanded" : false,
"children" : [
{
"text" : "Vydane",
"leaf" : true
},
{
"text" : "Prijate",
"leaf" : true
}
]
},{
"text" : "Já Živnostník",
"dbName" : "demo_de",
"leaf" : false,
"expanded" : false,
"children" : [
{
"text" : "Vydane",
"leaf" : true
},
{
"text" : "Prijate",
"leaf" : true
}
]
},{
"text" : "Nezisková organizace",
"dbName" : "demo_neziskova",
"leaf" : false,
"expanded" : false,
"children" : [
{
"text" : "Vydane",
"leaf" : true
},
{
"text" : "Prijate",
"leaf" : true
}
]
},{
"text" : "P?ísp?vková organizace",
"dbName" : "demo_prispevkovka",
"leaf" : false,
"expanded" : false,
"children" : [
{
"text" : "Vydane",
"leaf" : true
},
{
"text" : "Prijate",
"leaf" : true
}
]
},{
"text" : "Moje Firma SK s.r.o.",
"dbName" : "demo_sk",
"leaf" : false,
"expanded" : false,
"children" : [
{
"text" : "Vydane",
"leaf" : true
},
{
"text" : "Prijate",
"leaf" : true
}
]
}]}


When I try to get the text field, everything works fine, but when I try to get the dbName field, it returns undefined.


record.get('text') //returns the real value
record.get('dbName') //returns undefined

Can somebody help me, please?

Thanks for any answer

Fire-Dragon-DoL
25 Dec 2012, 9:21 PM
Hi,
I've got a following treestore:


Ext.define('Statistics.store.Menu', {
extend: 'Ext.data.TreeStore',
model: 'Menu',
storeId: 'MenuStore',
autoLoad: true,
autoSync: true,

proxy : {
type : 'ajax',
url : 'resources/scripts/get_menu.php?callback=1',
reader: {
type: 'json',
successProperty: 'success'
}
}


});


The get_menu.php script returns following JSON-formatted reply:



{"success": true,"children": [{"text": "Home","leaf": true},{
"text" : "Moje Firma s.r.o.",
"dbName" : "demo",
"leaf" : false,
"expanded" : false,
"children" : [
{
"text" : "Vydane",
"leaf" : true
},
{
"text" : "Prijate",
"leaf" : true
}
]
},{
"text" : "Já Živnostník",
"dbName" : "demo_de",
"leaf" : false,
"expanded" : false,
"children" : [
{
"text" : "Vydane",
"leaf" : true
},
{
"text" : "Prijate",
"leaf" : true
}
]
},{
"text" : "Nezisková organizace",
"dbName" : "demo_neziskova",
"leaf" : false,
"expanded" : false,
"children" : [
{
"text" : "Vydane",
"leaf" : true
},
{
"text" : "Prijate",
"leaf" : true
}
]
},{
"text" : "P?ísp?vková organizace",
"dbName" : "demo_prispevkovka",
"leaf" : false,
"expanded" : false,
"children" : [
{
"text" : "Vydane",
"leaf" : true
},
{
"text" : "Prijate",
"leaf" : true
}
]
},{
"text" : "Moje Firma SK s.r.o.",
"dbName" : "demo_sk",
"leaf" : false,
"expanded" : false,
"children" : [
{
"text" : "Vydane",
"leaf" : true
},
{
"text" : "Prijate",
"leaf" : true
}
]
}]}


When I try to get the text field, everything works fine, but when I try to get the dbName field, it returns undefined.


record.get('text') //returns the real value
record.get('dbName') //returns undefined

Can somebody help me, please?

Thanks for any answer

Model definition? We need it to check if you didn't forget to update fields there.

sveatlo
26 Dec 2012, 12:08 AM
Model:


Ext.define('Statistics.model.Menu', {
extend: 'Ext.data.Model',

fields: [
{name: 'text', type: 'string'},
{name: 'dbName', type: 'string'},
{name: 'leaf', type: 'boolean'},
{name: 'expanded', type: 'boolean', defaultValue: false}
],


});

skirtle
26 Dec 2012, 3:17 AM
Ext.define('Statistics.store.Menu', {
extend: 'Ext.data.TreeStore',
model: 'Menu',


Ext.define('Statistics.model.Menu', {

Your model names don't match.