PDA

View Full Version : Bug while repopulating the store



Lukich
31 Oct 2011, 12:14 PM
Hello. I have recently been asked to help out on a project that involves Ext JS, so I starting playing around with it and discovered the following bug. Not sure if this is a legitimate bug or just me doing something wrong. Basically, on page load I populate the panel with values and display them. Upon clicking on any of those fields in the view, the store should get emptied out and populated with a new set of values. All the code is listed below. However, once I removeAll() and do add(), even though everything works and view shows new values, I always get this error message:"Uncaught TypeError: Cannot read property 'internalId' of undefined" happening on this line: store.add(newData).
Any idea what might be causing it? I'm using Ext JS 4. Thank you! Luka

var arrayData = [
['Jay Gar','MD'],
['Aaron Baker','CA'],
['Susan Smith','NY'],
['Mary Stein','KT'],
['John Zalupic','WA'],
];

var store = Ext.create('Ext.data.ArrayStore',{
data: arrayData,
fields: ['personName', 'state']
});

var grid = Ext.create('Ext.grid.Panel', {
title: 'first grid',
renderTo: Ext.getBody(),
authoHeight:true,
width: 250,
store: store,
autoScroll: true,
columns: [
{ header: 'name', dataIndex: 'personName' },
{ header: 'st', dataIndex: 'state', sortable: false }
]
});

grid.getSelectionModel().on('selectionchange', function(sm, selectedRecord){
var newData = [
['Poka Boka', 'VK'],
['Choko Mok', 'CA']
];

store.removeAll();
store.add(newData);
});

mitchellsimoens
1 Nov 2011, 4:57 AM
I personally don't like ArrayStore but does this give you an error when you add data like this:


var newData = [
{ personName : 'Poka Boka', state : 'VK'},
{ personName : 'Choko Mok', state : 'CA'}
];

Lukich
2 Nov 2011, 3:59 PM
Unfortunately no, I still get the same error. Do you prefer jsonStore to ArrayStore or use some other solution?Thanks!Luka

mitchellsimoens
2 Nov 2011, 4:02 PM
I personally just use a regular Store

Lukich
2 Nov 2011, 4:12 PM
A user (http://stackoverflow.com/users/395890/amember) at Stackoverflow told me that add method expects records and I feed it an array and suggested I create a set of records to add using store.recordType. Is this a valid point, and if so, what's the Ext 4 version of recordType? I can't find recordType in documentation.

thank you.

mitchellsimoens
2 Nov 2011, 4:14 PM
You don't need to do that...

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store-method-add