简体   繁体   English

可以为JS模板增加价值[blueimp / jQuery-File-Upload]

[英]Hot to add value to the JS template [blueimp / jQuery-File-Upload]

I've got issue with jQuery File Upload (blueimp). 我在jQuery File Upload(blueimp)方面遇到问题。

On uploading files I insert file data to DB. 在上传文件时,我insert文件数据insert数据库。 Right after that I can get last insert id. 之后,我可以获得最后的插入ID。 The issue: How can i transmit this value from PHP to JavaScript Template? 问题:如何将该值从PHP传输到JavaScript模板?

To be more clear, I need template like: 更清楚地说,我需要类似以下模板:

<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>

where file.id is my last insert id that was defined in PHP. 其中file.id是我在PHP中定义的最后一个插入ID。

SOLUTUON : Function post in class UploadHandler. SOLUTUON :类UploadHandler中的函数发布。 Add something like 添加类似

$info[$index]->myvar= 'something';

then we can use file.myvar in template. 然后我们可以在模板中使用file.myvar

I had some extra form data, and I had luck with adding them to the function handle_file_upload 我有一些额外的表单数据,但很幸运将其添加到了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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM