javascript - Add records to Ext.data.ArrayStore - Stack Overflow

How can I add the following records (from the alert) into the Ext.data.ArrayStore?The mented out code

How can I add the following records (from the alert) into the Ext.data.ArrayStore? The mented 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);
        });

How can I add the following records (from the alert) into the Ext.data.ArrayStore? The mented 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);
        });
Share Improve this question asked Apr 1, 2014 at 21:22 JustBeingHelpfulJustBeingHelpful 19k39 gold badges168 silver badges251 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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/7a86L/

var arrayData = [
['Jay Garcia', 'MD'],
['Aaron Baker', 'VA'],
['Susan Smith', 'DC'],
['Mary Stein', 'DE'],
['Bryan Shanley', 'NJ'],
['Nyri Selgado', 'CA']
];
var store = Ext.create('Ext.data.ArrayStore', {
data : arrayData,
fields : ['personName', 'state']
});



console.log(store.first().data)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745211178a4616849.html

相关推荐

  • javascript - Add records to Ext.data.ArrayStore - Stack Overflow

    How can I add the following records (from the alert) into the Ext.data.ArrayStore?The mented out code

    16小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信