我想初始化fileinput的時候直接現實已有的圖片,這個圖片是從ajax訪問得到的,而且是一個數組。
$.get(url,function(res){
//图片地址是res.img,这是一个数组
$("#fileupload").fileinput({
initialPreview: [
//发现这里不能使用for循环res.img,应该怎么办?
],
initialPreviewAsData: true,
deleteUrl: "/site/file-delete",
overwriteInitial: true,
})
})
以下是原型:
$.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,
})
})
以下是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明明可以直接接收數組,我上面的json資料也顯示img確實是數組,但為什麼下面這樣寫後,卻把所有數字組合並成了一個?
$.get(url,function(res){
$("#fileupload").fileinput({
initialPreview: [
res.img
],
initialPreviewAsData: true,
deleteUrl: "/site/file-delete",
overwriteInitial: true,
})
})
最後得到的結果卻是
<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;">
正確的應該是兩張圖片才對啊
雷雷