gpt4 book ai didi

javascript - 当使用 ASP MVC 帮助程序持久_if_渲染时,Telerik Kendo UI 网格错误地序列化工具栏按钮

转载 作者:行者123 更新时间:2023-12-03 10:10:37 25 4
gpt4 key购买 nike

请注意:在持久化和恢复网格状态之前,一切都按预期完美运行。所以请不要在那里搜索错误...

使用 ASP MVC 助手渲染网格:

.ToolBar(toolbar => toolbar.Create().Text("Add new role"))

使用标准语句持久化网格客户端时:

    grid = $("#grid").data("kendoGrid");
data = kendo.stringify(grid.getOptions());

数据将部分无效,尤其是工具栏部分:(数据变量中JSON文本的一部分)

   ..."toolbar":{"command":[{"name":null,"buttonType":"ImageAndText","text":"Add new role"}]}...

注意“name”属性的空值。该值应该是“创建”。因此,恢复数据将破坏工具栏。

我花了很多时间在公共(public) JavaScript 版本中重现此内容,但是这个问题不能用纯 Html/Javascript 版本重现,因为它使用默认的工具栏定义,如下所示:

 ...,
toolbar: ["create"],
...

它将在数据中序列化为:

 "toolbar":["create"]

这与我们在 ASP MVC 案例中看到的有很大不同,而且它是正确的。另外,如果我们在 Html/javascript 中显式设置命令名称,例如:

  ...,
toolbar: [{name: "create", text: "Add new Customer"}],
...

它将被序列化为:

 "toolbar":[{"name":"create","text":"Add new Customer",

这是正确的,并且与我们在 ASP MVC 版本中看到的不同。

明显的解决方法是在 ASP MVC 中显式设置命令名称,但不幸的是 ASP MVC 帮助程序不会公开此属性...

知道要修补什么或如何解决?

最佳答案

据我所知,HtmlAttributes 使之成为可能,但是当你使用grid.getOptions时,json结果将不会像你期望的那样。因为 getOptions 将返回网格定义,而不是网格的渲染方式。

试试这个

.ToolBar(toolbar => toolbar.Create()
.Text("Add new role")
.HtmlAttributes(new {name = "create" }))

JSON 字符串将是这样的

 ..."toolbar":{"command":[{"name":null, "attr" : "\"name\" = \"create\"", "buttonType":"ImageAndText","text":"Add new role"}]}...

您可以使用字符串replace对其进行一些修改,使其符合您的预期

关于javascript - 当使用 ASP MVC 帮助程序持久_if_渲染时,Telerik Kendo UI 网格错误地序列化工具栏按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30127251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com