我想将Kendo模板作为变量传递给Template Javascript Function,以将JS函数的返回值注入到span的类中。 (对象是动态设置图标)。
如:#=addFileExtensionIcon(#=DocType#)#
当前迭代导致加载gif无限期持久...
我可以这样做吗?如果没有,我有什么选择?
@*//WF ITEM ATTACHMENTS TEMPLATE*@
<script id="itemAttachmentsTemplate" type="text/x-kendo-template">
<div class="attachment">
<span class='k-icon #=addFileExtensionIcon(#=DocType#)#'></span>
<h3>FILE NAME</h3>
<h3>#=DocType#</h3>
<h3>#=CreatedByUserName#</h3>
<div class="btn btn-link" id="">
<span class="k-icon k-i-download"> </span>
</div>
</div>
</script>
Js:
function addFileExtensionIcon(extension) {
switch (extension) {
case '.jpg':
case '.img':
case '.png':
case '.gif':
return ".k-i-image";
case '.doc':
case '.docx':
return ".k-i-file-doc";
case '.xls':
case '.xlsx':
return ".k-i-file-xls";
case '.pdf':
return ".k-i-file-pdf";
case '.zip':
case '.rar':
return ".k-i-file-zip";
default:
return ".k-i-file";
}
}
答案 0 :(得分:1)
以此替换您的代码。
<script id="itemAttachmentsTemplate" type="text/x-kendo-template">
<div class="attachment">
<span class='k-icon #=addFileExtensionIcon(DocType)#'></span>
<h3>FILE NAME</h3>
<h3>#=DocType#</h3>
<h3>#=CreatedByUserName#</h3>
<div class="btn btn-link" id="">
<span class="k-icon k-i-download"> </span>
</div>
</div>