[英]Hot to add value to the JS template [blueimp / jQuery-File-Upload]
我在jQuery File Upload(blueimp)方面遇到問題。
在上傳文件時,我insert
文件數據insert
數據庫。 之后,我可以獲得最后的插入ID。 問題:如何將該值從PHP傳輸到JavaScript模板?
更清楚地說,我需要類似以下模板:
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<div class="template-download fade" id="file-{%=file.id%}">
<div class="name"><span>{%=file.name%}</span></div>
....
</div>
{% } %}
</script>
其中file.id
是我在PHP中定義的最后一個插入ID。
SOLUTUON :類UploadHandler中的函數發布。 添加類似
$info[$index]->myvar= 'something';
然后我們可以在模板中使用file.myvar
。
我有一些額外的表單數據,但很幸運將其添加到了handle_file_upload
函數中
$file = new stdClass();
$file->name = $this->trim_file_name($name, $type, $index);
$file->size = $this->fix_integer_overflow(intval($size));
$file->type = $type;
//add additional post variables here:
$file->title = $_POST['title'][$index];
$file->description = $_POST['description'][$index];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.