Kendo UI 网格 - 客户端模板:转义 # 符号

Kendo UI Grid - Client Template: Escaping # sign

我正在使用 Kendo UI 的网格,以及 Twitter Bootstrap。

Twitter Bootstrap 有一个内置的 pop-up/modal 可以调用:

<a href="#" class="text-yellow" data-toggle="modal" data-target="#login">Login</a>

在我的 Kendo UI 网格中,我有一个自定义列模板:

   columns.Template(e => { }).ClientTemplate("<span data-toggle='modal' data-target='#login' title='Flag Animals as Dead or Deceased' style='cursor:pointer;' class='glyphicon glyphicon-flag flag-dead text-red'></span>").Width(50);

这是我遇到问题的地方,如果您注意到了,您需要使用# 符号指定模态 window 的 ID。即data-target='#login'

每当我的网格模板中出现 # 符号时,网格就会中断。我怎样才能摆脱这个标志?

您可以像这样使用 \ 字符转义 # data-target='\#login'

更新: 来自 telerik 文档 kendo templates

If your template includes a literal # character, which is not part of a binding expression and is not a script code marker, then you must escape that character or it will cause a template compilation error. For example, this can happen if a # is used inside a hyperlink URL or a CSS color value. Literal # in Javascript strings are escaped with \#, while literal # in external HTML script templates are escaped with \#.