ExtJs。 JsonStore.insert() 导致异常
我有一个带有工具栏按钮的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试关闭商店中的自动保存选项。
有关详细信息,请参阅示例 http://dev.sencha.com/deploy/ dev/examples/writer/writer.html
try to switch off the autoSave opiton in the Store.
see example for more info http://dev.sencha.com/deploy/dev/examples/writer/writer.html