ExtJs。 JsonStore.insert() 导致异常

发布于 2024-10-11 15:33:05 字数 1343 浏览 9 评论 0原文

我有一个带有工具栏按钮的 EditorGridPanel 来添加新记录。除了一种情况外,一切正常。当我尝试插入数据库中已存在的记录时,服务器发回:

{"success":false,"message":"already exists","data":{}}

但是 grid 创建一个标有红色三角形的新行。如果之后我尝试插入一条新记录(即使数据库中不存在),则服务器端一切正常,但我在 firebug 中收到“未捕获的异常”。它说:

'uncaught exception: Ext.data.DataReader: #realize was called with invalid remote-data. Please see the docs for DataReader#realize and review your DataReader configuration.'

这是为什么呢?

编辑 我发现:

当我尝试插入新记录时,我使用插入方法,该方法将带有参数 data 的 post 请求发送到服务器(编码为 true,listful 为 true):

data    [{"Name":"123"}]

并且它从服务器获取:

{"success":true,"data":{"PositionId":"eef1d9f3-9fdf-4b87-9f6c-ef42231f4fed","Name":"123"}}

之后我尝试创建一个具有相同名称的项目:

data    [{"Name":"123"}]

所以我得到:

{"success":false,"message":"already exists","data":{}}

来自服务器。

下次我尝试创建正确的项目时,商店会发送包含 2 个项目的数组

data    [{"Name":"1234"},{"Name":"123"}]

,但服务器仅创建第一个(最新)项目并发回:

{"success":true,"data":{"PositionId":"1ff05c7f-d5fc-41cd-81f3-faabc225b2a6","Name":"1234"}}

因此可能会发生错误,因为商店要求服务器创建 2 个项目,但只发送了一个后退。

那么该如何处理呢?是否可以让商店不再发送失败商品的请求?

I have an EditorGridPanel with toolbar button to add new records. Everything works fine except one scenario. When I try to insert a record which already exists in database, server sends back:

{"success":false,"message":"already exists","data":{}}

but grid creates a new row marked with red triangle. If after that I try to insert a new record (even if it doesn't exist in database), everything works fine on the server side, but i get an 'uncaught exception' in firebug. It says:

'uncaught exception: Ext.data.DataReader: #realize was called with invalid remote-data. Please see the docs for DataReader#realize and review your DataReader configuration.'

why is that?

EDIT
I have found that:

When I try to insert a new record I use insert method which sends post request with parameter data to server (encode is true, listful is true):

data    [{"Name":"123"}]

and it gets from server:

{"success":true,"data":{"PositionId":"eef1d9f3-9fdf-4b87-9f6c-ef42231f4fed","Name":"123"}}

after that I try to create an item with the same name:

data    [{"Name":"123"}]

so I get:

{"success":false,"message":"already exists","data":{}}

from server.

The next time I try to create the right item the store sends array with 2 items

data    [{"Name":"1234"},{"Name":"123"}]

but server creates only the first (newest) item and sends back:

{"success":true,"data":{"PositionId":"1ff05c7f-d5fc-41cd-81f3-faabc225b2a6","Name":"1234"}}

So the error may occur because store asks server to create 2 items, but only one is send back.

So how to deal with it? is it possible to make store not to send the request for failed item again?

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

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

发布评论

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

评论(1

爱你是孤单的心事 2024-10-18 15:33:05

尝试关闭商店中的自动保存选项。

    this.store = new Ext.data.Store({
        id: 'store'
        ,autoSave: false 
        ,autoLoad: true
        ,writer: writer,  
        ,proxy: proxy
        ,reader: reader
        scope       : this
    });

有关详细信息,请参阅示例 http://dev.sencha.com/deploy/ dev/examples/writer/writer.html

try to switch off the autoSave opiton in the Store.

    this.store = new Ext.data.Store({
        id: 'store'
        ,autoSave: false 
        ,autoLoad: true
        ,writer: writer,  
        ,proxy: proxy
        ,reader: reader
        scope       : this
    });

see example for more info http://dev.sencha.com/deploy/dev/examples/writer/writer.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文