jqGrid saveRow 带有错误函数
这可能是一个由两部分组成的问题。第一个是“我做错了什么”,第二个是“这是正确的方法吗?”。无论如何...
我正在尝试使用 jqgrid 保存已编辑的行,并且出于某种我尚未确定的原因,我无法使用 内联编辑。
table.saveRow(rowId,
false,
false,
optionalParams,
false,
function () { common.ShowMeSomething("error fired"); },
false);
ShowMeSomething 现在所做的只是发出警报,没什么大不了的,但不会触发。我已经尽可能地打开了源代码,它是一个带有完整功能的 $.extend: function(res,stat) ——我试图用 return Json(new { res = "hi", stat = false }) ,但没有运气沿着 javascript 来触发错误事件。运气不好。
另外,有更好的方法吗?出于验证原因,我需要返回错误。
This might be a 2 part question. First one is "what am I doing wrong" and 2nd is "is this the right way?". Anyway...
I'm attempting to save an edited row with jqgrid and for some reason I've yet to identify, I can't get the error event to fire using inline editing.
table.saveRow(rowId,
false,
false,
optionalParams,
false,
function () { common.ShowMeSomething("error fired"); },
false);
All ShowMeSomething does is an alert right now, no big deal, but will not fire. I've went as far as opening up the source, and it's an $.extend with complete: function(res,stat) -- I've attempted to mimic those with a return Json(new { res = "hi", stat = false }) with no luck on it walking down the javascript to fire off the error event. No luck.
Also, is there a better way to do this? I need the errors back for validation reasons.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题在于文档不明确。在某些网格功能中,错误 == false 且成功 == true,但情况并非如此。第一个参数是 rowId,第二个参数是对服务器的成功调用(基本上,它是否存在以及我是否收到了 http 响应),其中我所期望的内容是为完全失败而保留的无法创建。
将函数移动到第二个参数并从结果中进行错误处理可以实现我想要的——简单返回 Json(whateverObject) 并从那里执行需要完成的操作,例如重置、显示错误等。
The problem was unclear documentation. In some of the grids functionality, error == false and success == true which is not the case. The first parameter is the rowId, the second is a successful call to the server (basically, does it exist and did I get an http response) where what I expected is reserved for utter failures that I wasn't able to create.
Moving the function to this second parameter and doing the error handling from the result allows for what I wanted -- simple return Json(whateverObject) and do what needs to be done from there such as reset, show errors, etc.
您不包含产生错误的 jqGrid 代码和 MVC 控制器操作代码。所以我只能猜测你的问题的原因是什么。
服务器部分的一个原因可能是您尝试将错误作为
Json(...)
返回,而不更改 HTTP 响应状态代码 到错误代码。如果出现错误,您可以使用HttpContext.Response.StatusCode = 500
等代码设置响应代码,或使用 HttpException。客户端的另一个可能的原因是您尝试保存当前未编辑的行 editRow。方法 editRow 设置附加属性 "editable"=" 1" 用于编辑行, saveRow 仅保存具有此属性的行。
如果您在问题正文中包含更多客户端和服务器代码,则可以更好地帮助您。
You don't include the code of your jqGrid and the code of MVC controller action which produce the error. So I could only guess what is the reason of your problem.
One reason in the server part could be that you try to return the error as a
Json(...)
and not change the HTTP response status code to an error code. In case of an error you can either set the response code with the code likeHttpContext.Response.StatusCode = 500
or use HttpException.Another possible reason on the client side is that you try to save a row which is not currently edited with respect of editRow. The method editRow set additional attribute "editable"="1" for the editing row and saveRow save only the row having this attribute.
It you would be include more client and server code in the body of your question one could better help you.