jQuery使用Javascript模板引擎 [英] Javascript Template Engine Use with jQuery
问题描述
全部, 我正在尝试使用jQuery File Upload Demo: http://blueimp.github.com/jQuery-File-Upload/ >
我的问题是,它在文档中说它使用Javascript模板引擎( 我正在使用jQuery Tmpl代码( https://github.com/jquery/jquery-tmpl ),当我尝试在Wordpress博客中创建此代码时,在以下几行的jquery.fileupload-ui.js文件中出现一些错误: 在此文件中,此文件的定义如下:uploadTemplateId:'template-upload', 我很困惑为什么这不起作用,或者甚至如何使用我自己的javascript模板来做到这一点?当我尝试将这些文件复制到我的Wordpress博客中时,它总是会失败,并且我不认为我要复制的唯一东西是初始下载中的package.JSON和.gitignore文件.这些文件起什么作用?只是试图了解这个模板是什么以及如何使用它? 任何您可以提前告知我的信息,我们将不胜感激!感谢您的帮助! 我对该错误的最佳猜测是插件与您在wordpress上已经拥有的脚本文件之间的冲突. 您可以发布实际的错误消息吗? All,
I'm trying to use the jQuery File Upload Demo:
http://blueimp.github.com/jQuery-File-Upload/ My question is that it says in the Documentation that it uses the Javascript Template Engine (https://github.com/blueimp/jQuery-File-Upload/wiki/Template-Engine) However, I'm not familiar with this process. I'm trying to integrate this into my Wordpress blog to allow file uploads this way. Within the index.html it has the following Template defined: I'm using the jQuery Tmpl code (https://github.com/jquery/jquery-tmpl) and when I try and create this in my Wordpress blog I get some errors in my jquery.fileupload-ui.js file on these lines: Earlier in this file this is defined as this: uploadTemplateId: 'template-upload', I'm confused why this wouldn't work or even how to use my own javascript template to do this? When I try and copy these files into my Wordpress blog it always fails and the only thing I don't think I copy is the package.JSON and the .gitignore files in the initial download. What significance do these files play? Just trying to understand what this template is and how to use it? Anything you can point me to in advance is greatly appreciated! Thanks for the help! My best guess for the error is a clash of script files between the plugin and what you already have on wordpress. Could you post the actual error message(s)? 这篇关于jQuery使用Javascript模板引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!_initTemplates: function () {
var options = this.options;
options.templateContainer = document.createElement(
this._files.prop('nodeName')
);
options.uploadTemplate = tmpl(options.uploadTemplateId);
options.downloadTemplate = tmpl(options.downloadTemplateId);
},
.gitignore
是源代码控制文件,与脚本无关-请参见 https://github.com/jquery/plugins.jquery.com#readme 了解更多信息.<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>
_initTemplates: function () {
var options = this.options;
options.templateContainer = document.createElement(
this._files.prop('nodeName')
);
options.uploadTemplate = tmpl(options.uploadTemplateId);
options.downloadTemplate = tmpl(options.downloadTemplateId);
},
.gitignore
is a source control file and not relevant to the scripts - see http://help.github.com/ignore-files/ for more info.package.JSON
is a metadata file for jquery plugins for use by the new jquery plugin site and is nothing to do with the functioning of the plugin you are trying to use - see https://github.com/jquery/plugins.jquery.com#readme for more info.