PDA

View Full Version : Record.creaye() ?show" Uncaught TypeError: Cannot read property 'items' of undefine "



softball
18 Jul 2014, 1:12 AM
Dear ?
I try to read Array to store.
I use a sample as fellow?But it show
Uncaught TypeError: Cannot read property 'items' of undefined
in console.

I check it, and find it's woring in " var Customer = Ext.data.Record.create(["
but, I don;t know why?
somebody can help me?
thx.



Ext.onReady(function(){
var customers = [
[1, "David Wang", 27, "Programmer", "1983-01-01"],
[2, "Mary Chen", 25, "Sales", "1985-11-22"],
[3, "Christina Zung", 22, "Accountant", "1988-03-28"],
[4, "Joe Fun", 30, "Lawyer", "1980-05-10"]
];


var Customer = Ext.data.Record.create([
{ name:'id', type:'int', mapping:0 },
{ name:'name', type:'string', mapping:1 },
{ name:'age', type:'int', mapping:2 },
{ name:'occupation', type:'string', mapping:3 },
{ name:'dob', type:'string', mapping:4, dataFormat:'Y-m-d' }
]);

var customerReader = new Ext.data.ArrayReader({idIndex:0},Customer);

/* non-proxy way
var customerStore = new Ext.data.Store({
reader:customerReader
});
customerStore.loadData(customers);
*/

// proxy way
var customerProxy = new Ext.data.MemoryProxy(customers);
var customerStore = new Ext.data.Store({
proxy:customerProxy,
reader:customerReader
});
customerStore.load();

console.debug(customerStore.getAt(1).get('name'));
});

Gary Schlosberg
24 Jul 2014, 8:30 AM
In which version of ExtJS are you running this?

softball
24 Jul 2014, 4:09 PM
Dear? I running it in the Extjs 4.2.

softball
29 Jul 2014, 12:56 AM
Dear?
I had chaged the Customer as Array object?the it pass.
but?there are 2 Question ?

Q1.non-proxy:
if i use non-proxy way ,it show "cannot read property 'getProxy' of undefined"
why? how to solve it?

Q2.proxy way?
when I use console.debug(customerStore.getCount());
it show 0. why? the data of customers doesn't been loaded.

And? console.debug(customerStore.getAt(1).get('name'));
it show "Uncaught TypeError: Cannot read property 'get' of undefined " ?

help!!!




var customers = [
[1, "David Wang", 27, "Programmer", "1983-01-01"],
[2, "Mary Chen", 25, "Sales", "1985-11-22"],
[3, "Christina Zung", 22, "Accountant", "1988-03-28"],
[4, "Joe Fun", 30, "Lawyer", "1980-05-10"]
];

//-------->CHAGE TO THIS -->OK PASS
var Customer = Ext.data.Record.create(
{ name:'id', type:'int', mapping:0 },
{ name:'name', type:'string', mapping:1 },
{ name:'age', type:'int', mapping:2 },
{ name:'occupation', type:'string', mapping:3 },
{ name:'dob', type:'string', mapping:4, dataFormat:'Y-m-d' }
);


var customerReader = new Ext.data.ArrayReader({idIndex:0},Customer);

// non-proxy way-----------Q1.
var customerStore =Ext.create('Ext.data.Store', {reader:customerReader}
);

customerStore.loadData(customers);
console.debug(customerStore.getAt(1).get('name'));


// proxy way----------Q2.

var customerProxy = new Ext.data.MemoryProxy(customers);
var customerStore = new Ext.data.Store({
proxy:customerProxy,
reader:customerReader
});
customerStore.load();

// console.debug(customerStore.getAt(1).get('name'));
console.debug(customerStore.getCount());