Search code examples
postextjs4store

ExtJs 4 POST array of records from store


I have a simple rest store and after filling it with several records I am trying to send post request to server with array of records by calling create function. The POST request is sent but only with one record instead of array of records. UPDATE - I forgot to mention that this record has fields with empty values, and that is strange too, because I am filling store with values.

I stalled. Please give me a light where did I go wrong. Thanks.

My code samples:

Ext.define('my.store.testStore',{
    extend: 'Ext.data.Store',
    storeId: 'teststore',
    model: 'my.model.testModel',
    proxy: {
        type: 'rest',
        url: 'http://someurl.ru',
        reader: 'json'
    }
});

Ext.define('my.model.testModel',{
    extend: 'Ext.data.Model',
    fields: [
      {name: 'name', type: 'string'},
      {name: 'phone', type: 'string'},
      {name: 'email', type: 'string'}
    ]
});

var namesList = [Ext.create('my.model.testModel',{
  'name':'test name1',
  'phone':'343-343',
  'email':'[email protected]'
}),
Ext.create('my.model.testModel',{
  'name':'test name2',
  'phone':'6345',
  'email':'[email protected]'
}),
Ext.create('my.model.testModel',{
  'name':'test name2',
  'phone':'24324',
  'email':'[email protected]'
})
];

var testStore = Ext.create('my.store.testStore');
testStore.loadData(namesList);
testStore.create();

Solution

  • After a great time, this issue appeared again so I had to solve it anyway. And finally I succeeded to find working solution. The point is was just to add batchActions: true to store. Like this:

    Ext.define('my.store.testStore',{
        extend: 'Ext.data.Store',
        storeId: 'teststore',
        model: 'my.model.testModel',
        proxy: {
            type: 'rest',
            url: 'http://someurl.ru',
            reader: 'json',
            batchActions: true
        }