如何禁用 ExtJS 中 Store 的自动同步

发布于 2025-01-01 13:01:34 字数 1902 浏览 1 评论 0原文

ExtJS 版本是 ext-4.0.7-gpl。

同步商店时,服务器以 JSON 格式返回相同的对象,但填充了生成的 Id,我需要将其放入商店数据中。标识符位于封闭的实体中,如下所示:

{
    "id": 46,
    "name": "Excel",
    "typeExt": [{
        "ext": "xls",
        "id": "137",
        "isMain": "false",
    }, {
        "ext": "xslx",
        "id": "136",
        "isMain": "false",
    }]
}

因此 ids 137136 是在服务器端生成的。

我试图在商店的代理中创建它(编辑:Ajax 类型) (这本身可能是错误的):

proxy.afterRequest = function(request) {
     if (request.action === 'create' && request.records.length == 1) {
         me.store.autoSync = false;
         var created = Ext.JSON.decode(request.operation.response.responseText);
         request.records[0].set('id', created.id);
         request.records[0].set('typeExt', created.typeExt);
         //request.records[0].modified = {};
         //request.records[0].dirty = false;
         me.store.autoSync = true;
     }
     if (request.action === 'update' && request.records.length == 1) {
         var updated = Ext.JSON.decode(request.operation.response.responseText);
         me.store.autoSync = false;
         request.records[0].set('typeExt', updated.typeExt);
         me.store.autoSync = true;
     }

 };

请参阅评论的变体。

如果我不将 autoSync 设置为 false,它将无限循环。

如果我不清除这些read-only字段modifieddirty,则修改后的记录将包含在下一个同步请求中(如果我编辑了)另一个记录,它发送一个记录数组,这会破坏我的服务器端服务。

如果我清除 dirtymodified (如注释行中所示),则更新操作仅有效一次。我按 RowEditing 插件对话框中的“更新”按钮,但它永远不会第二次向服务器发送所需的请求。

在后一种情况下,我想我通过手动编辑只读字段破坏了某些东西,但我找不到什么。

人们通常如何处理此类问题?

PS。

request.records[0].commit(true); || request.records[0].editing = false; 

|| request.records[0].beginEdit(); 

也曾尝试过,但没有成功。

ExtJS version is ext-4.0.7-gpl.

When syncing a Store, the server returns me the same object in JSON format, but populated with generated Ids, that I need to put into my store data. The identifiers are in enclosed entities, like this:

{
    "id": 46,
    "name": "Excel",
    "typeExt": [{
        "ext": "xls",
        "id": "137",
        "isMain": "false",
    }, {
        "ext": "xslx",
        "id": "136",
        "isMain": "false",
    }]
}

So the ids 137 and 136 are generated on server-side.

I am trying to make it in a store's proxy (edit: Ajax type) (which itself could be wrong):

proxy.afterRequest = function(request) {
     if (request.action === 'create' && request.records.length == 1) {
         me.store.autoSync = false;
         var created = Ext.JSON.decode(request.operation.response.responseText);
         request.records[0].set('id', created.id);
         request.records[0].set('typeExt', created.typeExt);
         //request.records[0].modified = {};
         //request.records[0].dirty = false;
         me.store.autoSync = true;
     }
     if (request.action === 'update' && request.records.length == 1) {
         var updated = Ext.JSON.decode(request.operation.response.responseText);
         me.store.autoSync = false;
         request.records[0].set('typeExt', updated.typeExt);
         me.store.autoSync = true;
     }

 };

See the commented variants.

If I don't set autoSync to false, it gets looped infinitely.

If I don't clear those read-only fields modified and dirty, the modified records are included in the next syncronization request, if I edited another record, it sends an Array of records which breaks my server-side service.

If I clear dirty and modified like it is shown in the commented lines, the update operation works only once. I press Update button in RowEditing plugin dialog, but it never sends the needed request to the server for the second time.

In the latter case I guess I broke something by hand-editing the readonly fields, but I can not find what.

How do people usually handle issues liek this?

PS.

request.records[0].commit(true); || request.records[0].editing = false; 

|| request.records[0].beginEdit(); 

Were tried with no seccess too.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘虞初梦 2025-01-08 13:01:34

虽然这对 Ext 4.0.7 没有多大好处,但 suspendAutoSyncresumeAutoSync 方法是在 Ext 4.1.0 中添加的。希望这对其他人有用。

While this won't do you much good on Ext 4.0.7, the suspendAutoSync and resumeAutoSync methods were added in Ext 4.1.0. Hopefully this will be useful to someone else.

不及他 2025-01-08 13:01:34

我在 Ext 4.0.7 的网格存储中使用了此方法,但在树存储中也遇到了类似的问题。所有这一切都通过直接代理(并且 autosync true)

如果您查看 Ext.data.Store::onCreateRecords 的代码,您将看到存储记录被从服务器返回的记录替换,前提是顺序相同。

所以,它非常简单:只需从服务器返回发送到 create 方法的相同 json/对象,但设置了 id,它应该在商店中自动更新它们。

我知道这没有多大帮助,但也许会给你一些指导。

我认为如果您提到以下内容会有所帮助:

  • 您正在使用的代理类型
  • 确切的分机版本
  • 也许是启动记录创建的代码

I have this working for grids stores with Ext 4.0.7, but having similar issues with tree stores. All this with a direct proxy (and autosync true)

If you look at the code of Ext.data.Store::onCreateRecords, you'll see that the store records are replaced by those returned from the server, given the order is the same.

So, it is pretty straight-forward: just return from the server the same json/object sent to the create method, but with the id set and it should update them automatically on the store.

I know this is of not much help, but perhaps will give you some direction.

I think it would help if you mention:

  • the type of proxy you're using
  • the exact ext version
  • perhaps the code initiating the creation of the record
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文