【问题标题】:extjs store id from server来自服务器的 extjs 存储 id
【发布时间】:2012-03-28 06:44:04
【问题描述】:

我尝试让 Ext.Data.Store 工作...

使用普通代理效果很好:

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

调用以下网址:

POST "http://localhost:3000/users?_dc=1332885308330" 删除“http://localhost:3000/users/1995?_dc=1332885308524”

我的服务器总是返回 1995 作为 id。

当我对商店尝试同样的事情时:

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

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

它调用这个网址:

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

为什么使用普通代理,内部 id 是正确的,而不是 store ...

这是我的模型、代理和商店配置:

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);

【问题讨论】:

    标签: extjs4 store


    【解决方案1】:

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

    此方法是否存在我在文档中找不到,可能需要使用

    store.removeAt(0);

    【讨论】:

    • removeAt 不起作用,请求未完成...有类似 commit 的东西吗?我以为是 sync() 但我在 javascript 控制台中没有看到任何 DELETE 请求...
    • 它有效,sync() 方法没有回调但是它是异步的,所以 remove() 为时过早...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-03
    • 2013-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-11
    • 2020-04-21
    相关资源
    最近更新 更多