我想初始化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;">
正确的应该是两张图片才对啊