Hello im new in Extjs and also in javascript. i hope you can help me by solving this problem, maybe its easy to solve but i have no more ideas. Here are my code
Code:
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'},
{name: 'age', type: 'int'},
{name: 'eyeColor', type: 'string'}
]
});
var store = Ext.create('Ext.data.Store',{
model: 'User',
proxy: {
type: 'ajax',
url : 'app/user.php',
reader: {
type: 'json',
model: 'User',
root: 'users'
}
},
});
This is the JSON that the user.php file returns
HTML Code:
{"users": [{"firstName" : "peter","lastName" : "parker","age" : 23,"eyeColor" : "brown",},{"firstName":"horst","lastName" : "lattek","age" : 21,"eyeColor":"green",}] }.
now my problem:
i want to get the 'firstName' of the second USER and my idea to solved it is:
var result = store.getAt(1);
result.get('firstName');
Firebug (i work on firefox) give the FAILURE: result.get() -> result is undefined.
and when i use store.count() to check the input of the store it returns "0" ??? why ???
when count is 0 i think there is a mistake in the PROXY READER and there is no mapping to the USER model ... but when i use this code:
Code:
store.load({
callback: function() {
//the user that was loaded
var user = store.first();
console.log("Name: " + user.get('firstName'))
}
});
the console gives me "peter" ??? also i think the json was read right ... please help me!
thank you ... mentizm!
i hope you understand everything ... its late in germany 