Home > Back-end > The bootstrap - the fileinput, many times to upload, previewId repetition
The bootstrap - the fileinput, many times to upload, previewId repetition
Time:01-28
[b] good intention person to help me, please have a look at the code What else is normal, the following code batch upload, echo, delete, echo mass upload again, normal, but there is a bug, Steps: to choose the image, click on the upload, then choose a picture; This id is used as a preview on id, cause my logic can't proceed,
The bootstrap - the fileinput document also look a little knowledge, tried a variety of monitoring events, also won't prototype operation, has been five days; I'm trapped died, solving solution, [/b]
Var carouselImgs=[]; Var fileNames=null; Var initialPreviewsPic=(fileNames? FileNames. Split (", ") : []); Var initialPreviewPic=[]; Var initialPreviewConfigPic=[]; for (var i=0; I & lt; InitialPreviewsPic. Length; I++) { Var fileName=initialPreviewsPic [I]; If (fileName!=null & amp; & The fileName!=' ') { Var delImg=new Object (); DelImg=generFilDel (fileName); InitialPreviewPic. Push (fileName); InitialPreviewConfigPic. Push (delImg); CarouselImgs. Push (fileName); } } $(" # goodsSide "). Val (carouselImgs);
$(" # the fileinput - goodsSide "). The fileinput ({
UploadUrl: prefix +/up, Enctype: "multipart/form - data ', ValidateInitialCount: true, FileActionSettings: { ShowRemove: true, ShowUpload: true, ShowDownload: true, }, //allowedPreviewTypes: []; PreviewFileType: [' image '], AllowedPreviewTypes: [' image '], InitialPreviewFileType: 'image',//'HTML', 'text', 'video' and 'audio', 'flash' and 'object'], InitialPreviewShowDelete: true, InitialPreview: initialPreviewPic, InitialPreviewConfig: initialPreviewConfigPic,//is used to set each item of important attributes configuration (set) as part of the Theme: 'explorer - fas, OverwriteInitial: false,//if we need to cover the initial preview the content and the subtitle Settings, InitialPreviewAsData: true,//whether the initial preview the content set resolved as data rather than the original tag Language: "useful",//configuration language ShowUpload: true,//show the overall upload button ShowRemove: false,//show the overall delete button Whether showClose: false,//display close button Asynchronous upload uploadAsync: true,// UploadLabel: "upload",//set the overall upload button characters //removeLabel: "remove",//delete button set whole Chinese characters UploadClass: "BTN BTN - warning",//set the upload button style Whether showCaption: false,//show the title DropZoneEnabled: false,//whether the display area of drag MaxFileSize: 0,//file size, MaxFileCount: 100,//to allow maximum upload number, can be multiple, AllowedFileExtensions: [" BMP, GIF, JPG, jpeg, PNG "],//, JPG, PNG, GIF, "docx", "zip", "XLSX", "TXT" MsgFilesTooMany: "choose the number of files uploaded ({n}) over the allowed maximum value of {m}!" , ShowBrowse: true, BrowseOnZoneClick: false, PreviewSettings: { Image: {width: 250 px!" Important ", height: "160 px! Important} "}, LayoutTemplates: { //actionUpload: "//remove small preview window the button }, })
On (" fileuploaded ", function (previewId event, data, index) { The console. The log (" upload to complete the trigger monitor events ") The console. The log (previewId) Var fileName=data. The response. The data; $(" # "+ previewId). Attr (" fileName", fileName); Var carouselImgs=$(" # goodsSide "). Val ()!=""? $(" # goodsSide "). Val (). The split (", ") : []; CarouselImgs. Push (fileName); $(" # goodsSide "). Val (carouselImgs); }) On (" filesuccessremove ", function (event, previewId, extra) { Var fileName=$(" # "+ previewId). Attr (" fileName"); Var carouselImgs=$(" # goodsSide "). Val ()!=""? $(" # goodsSide "). Val (). The split (", ") : []; Var newCarouselImgs=[]; for (var i=0; I & lt; CarouselImgs. Length; I++) { If (carouselImgs [I]!=fileName) NewCarouselImgs. Push (carouselImgs [I]); } CarouselImgs=newCarouselImgs; $(" # goodsSide "). Val (carouselImgs); }) on (' filepredelete ', function (the event, the key, the jqXHR, data) { # goodsSide removeHidden (key, ""); });
//modify the initial loading the type of file The function generFilDel (fileName) { Var o=new Object (); O. chua aption=fileName; O.u rl=prefix + "/del"; Referred ey=fileName; If (fileName==null | | fileName. The indexOf (". ")==1) { Return {" type ": null," fileType: null};
}
Var fileTyp=fileName. The split (". ") [1];
If ([BMP, GIF, JPG, jpeg, PNG "]. Join (", "). The indexOf (fileTyp)!=1) { O.t ype="image". O.f iletype="image/" + fileTyp; The return o; }
If ([" mp3 "]. Join (", "). The indexOf (fileTyp)!=1) { O.t ype="audio"; O.f iletype="audio/" + fileTyp; The return o; }
If ([" mp4 "]. Join (", "). The indexOf (fileTyp)!=1) { O.t ype="video". O.f iletype="video/" + fileTyp; The return o; }