0
votes

I try to make Ext.Data.Store working...

With a normal proxy it works great:

var user = Ext.create('User', {name: 'Ed Spencer', email: '[email protected]'});
user.save({
  callback: function(){
    arguments[0].destroy();
  }
});

Call the following urls:

POST "http://localhost:3000/users?_dc=1332885308330" DELETE "http://localhost:3000/users/1995?_dc=1332885308524"

My Server always return 1995 as id.

When I try the same thing with store:

var user = store.add({name: 'Ed Spencer', email: '[email protected]'});
store.sync();

store.destroy(store.getAt(0));
store.sync();

It calls this urls:

POST "http://localhost:3000/users?_dc=1332885308330" DELETE "http://localhost:3000/users/User-ext-record-2?_dc=1332885308326&id=User-ext-record-2"

Why with a normal proxy the internal id is the right and not with store ...

Here is my model, proxy and store configuration:

Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: ['id', 'name', 'email'],

    proxy: {
        type: 'rest',
        url : '/users',
        reader: {
          type: 'json',
          root: 'data',
          id: 'id'
        },
        writer: {
            type: 'json',
            writeAllFields: true,
            root: 'data',
            messageProperty: 'message'
        }
    },
});

var store = Ext.create('Ext.data.Store', {
    model: 'User',
});

EDIT:

It works with removeAt()

setTimeout(function(){
    store.removeAt(0);
    store.sync();
}, 2000);
1

1 Answers

1
votes

store.destroy(store.getAt(0));

does this method exists i can't find it in the docs, may be you need to use

store.removeAt(0);