extjs хранит идентификатор с сервера - PullRequest
0 голосов
/ 28 марта 2012

Я пытаюсь, чтобы Ext.Data.Store работал ...

С обычным прокси он прекрасно работает:

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

Вызовите следующие URL:

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

Мой сервер всегда возвращает 1995 как идентификатор.

Когда я пытаюсь сделать то же самое с store:

var user = store.add({name: 'Ed Spencer', email: 'ed@sencha.com'});
store.sync();

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

Он вызывает следующие URL:

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

Почему при обычном прокси внутренний идентификатор правильный, а не с хранилищем ...

Вот моя модель, прокси иКонфигурация магазина:

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',
});

РЕДАКТИРОВАТЬ :

Работает с removeAt ()

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

1 Ответ

1 голос
/ 28 марта 2012

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

существует ли этот метод, я не могу найти его в документах, возможно, вам нужно использовать

store.removeAt (0);

...