Javascript模板引擎与jQuery一起使用

Javascript Template Engine Use with jQuery

本文关键字:一起 jQuery 引擎 Javascript      更新时间:2023-09-26

全部,我正在尝试使用jQuery文件上传演示:http://blueimp.github.com/jQuery-File-Upload/

我的问题是它在文档中说它使用Javascript模板引擎(https://github.com/blueimp/jQuery-File-Upload/wiki/Template-Engine)

然而,我对这个过程并不熟悉。我正在尝试将其集成到我的Wordpress博客中,以允许以这种方式上传文件。在index.html中,它定义了以下模板:

<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-upload fade">
        <td class="preview"><span class="fade"></span></td>
        <td class="name">{%=file.name%}</td>
        <td class="size">{%=o.formatFileSize(file.size)%}</td>
        {% if (file.error) { %}
            <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
        {% } else if (o.files.valid && !i) { %}
            <td>
                <div class="progress progress-success progress-striped active"><div class="bar" style="width:0%;"></div></div>
            </td>
            <td class="start">{% if (!o.options.autoUpload) { %}
                <button class="btn btn-primary">
                    <i class="icon-upload icon-white"></i> {%=locale.fileupload.start%}
                </button>
            {% } %}</td>
        {% } else { %}
            <td colspan="2"></td>
        {% } %}
        <td class="cancel">{% if (!i) { %}
            <button class="btn btn-warning">
                <i class="icon-ban-circle icon-white"></i> {%=locale.fileupload.cancel%}
            </button>
        {% } %}</td>
    </tr>
{% } %}
</script>

我使用的是jQuery Tmpl代码(https://github.com/jquery/jquery-tmpl)当我尝试在Wordpress博客中创建这个时,我在jquery.filelpload-ui.js文件中的以下几行出现了一些错误:

_initTemplates: function () {
        var options = this.options;
        options.templateContainer = document.createElement(
            this._files.prop('nodeName')
        );
        options.uploadTemplate = tmpl(options.uploadTemplateId);
        options.downloadTemplate = tmpl(options.downloadTemplateId);
    },

在该文件的早期,它被定义为:uploadTemplateId:"模板上传",

我很困惑为什么这不起作用,甚至不知道如何使用我自己的javascript模板来做到这一点?当我试图将这些文件复制到Wordpress博客中时,它总是失败,我认为我唯一没有复制的就是包。JSON和初始下载中的.gitignore文件。这些文件有什么意义?只是想了解这个模板是什么以及如何使用它?

如果你能提前给我指给我,我将不胜感激!谢谢你的帮助!

.gitignore是一个源代码管理文件,与脚本无关-请参阅http://help.github.com/ignore-files/了解更多信息。

package.JSON是jquery插件的元数据文件,供新的jquery插件网站使用,与您尝试使用的插件的功能无关-请参阅https://github.com/jquery/plugins.jquery.com#readme了解更多信息。

我对这个错误的最佳猜测是插件和wordpress上已有的脚本文件之间的冲突。

你能发布实际的错误消息吗?