Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
69
rated 0 times [  70] [ 1]  / answers: 1 / hits: 7006  / 10 Years ago, tue, april 1, 2014, 12:00:00

How can I add the following records (from the alert) into the Ext.data.ArrayStore? The commented out code (in newStore assignment) shows what data is set in the store originally and seems to work. The code in the loop shows what I've tried that did not work.



        var newStore = new Ext.data.ArrayStore({
fields: [
'id',
'value'

]
//data: [[1, 'x'], [2, 'y']]
});

//alert(records.toSource());

Ext.each(records, function(rec) {
alert(rec.get('id') + ' ... ' + rec.get('value'));
//newStore.data.add(rec);
//Ext.apply(newStore, rec);
});

More From » json

 Answers
1

The .add() expect a record object. If your objects in the Ext.each() are in the format



{
id:~~,
value:~~
}


simply calling newStore.add(rec); will work just fine.



If they are not you will need to build a psudo record by doing something like this:



Ext.each(records,function(rec){ 
newStore.add({id:rec.id,value:rec.value});
}


Here is a fiddle of a working example



http://jsfiddle.net/7a86L/


[#46364] Tuesday, April 1, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
richardaydenc

Total Points: 148
Total Questions: 125
Total Answers: 98

Location: Seychelles
Member since Mon, Jun 28, 2021
3 Years ago
;