1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| $(function () { var uploadListIns = layui.upload.render({ elem: '#testList' ,elemList: $('#demoList') ,url: '${request.contextPath}/file/upload' ,accept: 'file' ,multiple: true ,number: 10 ,auto: true ,done: function(res, index, upload){ var attachment = $("#attachment").val(); var attachmentArray = attachment ? attachment.split(",") : []; attachmentArray.push(res.uuid) $("#attachment").val(attachmentArray.join(",")) appendTr(res.uuid, res.fileName, res.fileId); return; } ,error: function(){ } });
<#list files as file> appendTr('${file.uuid}', '${file.fileName}', '${file.fileId}') </#list>
function appendTr(uuid, fileName, fileId) { let downloadUrl = '${request.contextPath}/file/download?fileId=' + fileId var tr = $(['<tr id="'+ uuid +'">' ,'<td>'+ '<a href="' + downloadUrl + '" style="color:blue; text-decoration:underline;">' + fileName + '</a>' +'</td>' ,'<td>' ,'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>' ,'</td>' ,'</tr>'].join(''));
tr.find('.demo-delete').on('click', function(){ var formData = new FormData(); formData.append("uuid", tr.attr('id')); $.ajax({ type: "post", async: false, url: '${request.contextPath}/file/remove', dataType: "json", data: formData, contentType: false, processData: false, success: function (res) { Array.prototype.removeByValue = function (val) { for (var i = 0; i < this.length; i++) { if (this[i] === val) { this.splice(i, 1); i--; } } return this; } var attachment = $("#attachment").val(); var attachmentArray = attachment ? attachment.split(",") : []; attachmentArray.removeByValue(tr.attr('id')); $("#attachment").val(attachmentArray.join(",")) }, error: function (err) { console.log(err) } }); tr.remove(); });
$('#demoList').append(tr); } var selectTreeXmSelect = layui.xmSelect.render({ el: '#selectTree', autoRow: true, name: "selectTree", radio: true, height: 'auto', data: [] }) $.ajax({ type: "get", async: false, url: Ams.ctxPath + "/demo/demo/selectTree", dataType: "json", data: {}, contentType: "application/json;charset=UTF-8", success: function(res) { selectTreeXmSelect.update({ data: res, tree: { show: true, strict: false, expandedKeys: true, }, }) selectTreeXmSelect.setValue(['${demo.selectTree!}']) }, error: function(err) { console.log(err) } }) });
|