0
votes

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();
2
Did you try to use loadRawData() instead of loadData()? - Darin Kolev
Yes, the result is the same - me1111

2 Answers

1
votes

You should use testStore.sync() insted of testStore.create()

Another things:

  1. testStore.create() - this function takes an object as first parameter and creates instance of the model then sends it to the server. In case if "create" is called without parameter then instance of the model is created based on values from fields defaultValue which by default is set to "", that is way you got response with empty values.
  2. About namesList. You forgot to add ")" to the 3-th model.

    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]'
    })//Here was missed ")"
    ];
    
0
votes

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
    }