我在上传 Ajax 中使用 initialPreview 时遇到问题。我从上传请求中返回了两个项目,但只会显示第一个项目。
枝条:
<div class="file-loading">
<input id="input-id" name="input-res-1" type="file" class="file" multiple data-browse-on-zone-click="true">
</div>
{% set uploadUrl = path('mytest_property_test_upload') %}
<script>
let inputEl = $("#input-id");
inputEl.fileinput(
{
uploadUrl: {{ uploadUrl|json_encode()|raw }},
initialPreviewAsData: true,
}
);
</script>
php:
/**
* @Route("/ajax/test-upload", name="mytest_property_test_upload")
*/
public function testUpload()
{
return new JsonResponse([
'initialPreview' => [
"https://picsum.photos/id/900/1920/1080",
"https://picsum.photos/id/901/1920/1080"
],
// initial preview configuration
'initialPreviewConfig' => [
['caption' => "Picture-3.jpg", 'description' => "desc", 'size' => 628782, 'width' => "120px", 'url' => "/site/file-delete", 'key' => 3],
['caption' => "Picture-4.jpg", 'description' => "desc", 'size' => 628782, 'width' => "120px", 'url' => "/site/file-delete", 'key' => 4],
],
'initialPreviewAsData' => true,
'append' => false
]);
}