KendoUI:如何打开Kendo网格超链接栏
KendoUI: How to open Kendo grid hyperlink column
我有一个带有超链接列的 kendo 网格。所需的行为是当我单击该列项目时,它会打开一个新选项卡并打开文档。此 kendo 网格包含文档列表,单击该行将打开文档。我可以通过以下模板打开文档
{ title: "Name", field: "Name", template: kendo.template("<a href='" + constants.serviceUrl + "Document/GetFileContents/#= DocumentId #' onclick='window.open(this.href); return false;'>#= Name #</a>") },
此模板在打开文档时效果很好,但上述模板的问题是在添加新文档时它会失效,因为那时我没有 DocumentId。
这是我想象的样子,但我觉得我在这个模板中遗漏了一些东西:
{ title: "Name", field: "Name", template: '<a href="\#" onclick="window.open(this.href); views.titleClick(this)" >#=Name#</a>' },
我已验证这两个标题都命中了服务层。上面的模板打开了一个新选项卡,但它并没有打开文档,而是重新加载了应用程序。需要帮助! :)
在四处寻找井号后,我发现我们可以在 Kendo 网格模板中编写 javascript。所以在传递 DocumentId 之前,我添加了检查它是否未定义。
工作代码如下所示:
{ title: "Name", field: "Name", template: kendo.template("<a href='" + constants.serviceUrl + "Document/GetFileContents/ # if (typeof(DocumentId) === 'undefined'){# -1 #} else {##= DocumentId##}#' onclick='window.open(this.href); return false;'>#= Name #</a>") },
我有一个带有超链接列的 kendo 网格。所需的行为是当我单击该列项目时,它会打开一个新选项卡并打开文档。此 kendo 网格包含文档列表,单击该行将打开文档。我可以通过以下模板打开文档
{ title: "Name", field: "Name", template: kendo.template("<a href='" + constants.serviceUrl + "Document/GetFileContents/#= DocumentId #' onclick='window.open(this.href); return false;'>#= Name #</a>") },
此模板在打开文档时效果很好,但上述模板的问题是在添加新文档时它会失效,因为那时我没有 DocumentId。
这是我想象的样子,但我觉得我在这个模板中遗漏了一些东西:
{ title: "Name", field: "Name", template: '<a href="\#" onclick="window.open(this.href); views.titleClick(this)" >#=Name#</a>' },
我已验证这两个标题都命中了服务层。上面的模板打开了一个新选项卡,但它并没有打开文档,而是重新加载了应用程序。需要帮助! :)
在四处寻找井号后,我发现我们可以在 Kendo 网格模板中编写 javascript。所以在传递 DocumentId 之前,我添加了检查它是否未定义。
工作代码如下所示:
{ title: "Name", field: "Name", template: kendo.template("<a href='" + constants.serviceUrl + "Document/GetFileContents/ # if (typeof(DocumentId) === 'undefined'){# -1 #} else {##= DocumentId##}#' onclick='window.open(this.href); return false;'>#= Name #</a>") },