正在寻找网上的答案,但找不到任何东西.这个代码小点真让我感到沮丧,因为我无法理解.(它是插件的一部分:jQuery文件上传)
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-download fade">
{% if (file.error) { %}
<td></td>
<td class="name"><span>{%=file.name%}</span></td>
<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
<td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
{% } else { %}
<td class="preview">{% if (file.thumbnail_url) { %}
<a href="{%=file.url%}" title="{%=file.name%}" rel="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a>
{% } %}</td>
<td class="name">
<a href="{%=file.url%}" title="{%=file.name%}" rel="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a>
</td>
<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
<td colspan="2"></td>
{% } %}
<td class="delete">
<button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}">
<i class="icon-trash icon-white"></i>
<span>{%=locale.fileupload.destroy%}</span>
</button>
<input type="checkbox" name="delete" value="1">
</td>
</tr>
{% } %}
</script>
Run Code Online (Sandbox Code Playgroud)
text/x-tmpl?{%和%}标签是什么?...但想知道关于这一切的一切.
Nib*_*Pig 62
x-tmpl没有实际意义,它只是阻止浏览器将脚本解释为javascript.
它主要用于jquery模板或knockoutjs模板绑定.
在某些时候,javascript数据对象将与模板一起使用以呈现一些html.数据对象中的值将替换模板中标有{%}和类似值的值,其中一些{%}部分反映代码流,如循环等.
我不确定哪个模板库使用{%}但是,它不是jquery模板,jsrender或knockout.您必须检查示例代码中引用的库.
Que*_*tin 11
那么text/x-tmpl是什么类型的?
非标准的.看起来像一个模板.
这些{%和%}标签是什么?
模板语言的一部分.
什么解析器执行此代码?
可能是用JavaScript编写并在<script>同一页面上的另一个元素中导入的.
| 归档时间: |
|
| 查看次数: |
42070 次 |
| 最近记录: |