Saya mahu terus memaparkan imej sedia ada apabila memulakan input fail Imej ini diakses daripada ajax dan merupakan tatasusunan.
$.get(url,function(res){
//图片地址是res.img,这是一个数组
$("#fileupload").fileinput({
initialPreview: [
//发现这里不能使用for循环res.img,应该怎么办?
],
initialPreviewAsData: true,
deleteUrl: "/site/file-delete",
overwriteInitial: true,
})
})
Berikut ialah prototaip:
$.get(url,function(res){
$("#fileupload").fileinput({
initialPreview: [
'http://upload.wikimedia.org/wikipedia/commons/thumb/e/e1/FullMoon2010.jpg/631px-FullMoon2010.jpg',
'http://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Earth_Eastern_Hemisphere.jpg/600px-Earth_Eastern_Hemisphere.jpg'
],
initialPreviewAsData: true,
deleteUrl: "/site/file-delete",
overwriteInitial: true,
})
})
Berikut ialah data json
{goods_id: 9, goods_name: "产品测试4", cat_id: 40, sku_id: "888888888888", goods_encode: "77777777777",…}
addtime:1496837803
cat_id:40
goods_barcode:"66666666666"
goods_desc:null
goods_encode:"77777777777"
goods_id:9
goods_image:"/uploads/product/20170607/d60bf37e6c381c8b52be22e63217bc1c.jpg;/uploads/product/20170607/2cb078c49125ff42fbf13bee19a0e64c.jpg;"
goods_name:"产品测试4"
img:["/uploads/product/20170607/d60bf37e6c381c8b52be22e63217bc1c.jpg",…]
0:"/uploads/product/20170607/d60bf37e6c381c8b52be22e63217bc1c.jpg"
1:"/uploads/product/20170607/2cb078c49125ff42fbf13bee19a0e64c.jpg"
index:1
size:["37", "33", "35", "38", "39"]
sizes:"37,33,35,38,39"
sku_id:"888888888888"
status:1
updatetime:null
InitialPreview jelas boleh menerima tatasusunan secara langsung Data json saya di atas juga menunjukkan bahawa img sememangnya tatasusunan, tetapi mengapa selepas menulis seperti ini, semua tatasusunan digabungkan menjadi satu?
$.get(url,function(res){
$("#fileupload").fileinput({
initialPreview: [
res.img
],
initialPreviewAsData: true,
deleteUrl: "/site/file-delete",
overwriteInitial: true,
})
})
Keputusan akhir ialah
<img src="/uploads/product/20170607/d60bf37e6c381c8b52be22e63217bc1c.jpg,/uploads/product/20170607/2cb078c49125ff42fbf13bee19a0e64c.jpg" class="file-preview-image kv-preview-data" title="Desert.jpg" alt="Desert.jpg" style="width:auto;height:160px;">
Yang betul hendaklah dua gambar