一、前言
- 需要在数据表格每一行加一个
上传 按钮 - 问题:
点击上传,弹出选择文件框了,选择 打开(O) 之后并没有执行上传操作
二、html 部分代码
<script type="text/html" id="uploadPicTpl">
<a class="layui-btn layui-btn-normal layui-btn-xs upload-pic">
上传
</a>
</script>
三、js 部分代码
layui.define(function(exports) {
layui.use(['layer', 'table','upload'], function () {
let $ = layui.$
,layer = layui.layer
,table = layui.table
,upload = layui.upload;
table.render({
elem: '#LAY-user-table'
,url: '/././.'
,cols: [[
{type: 'checkbox', fixed: 'left'}
,{field: 'id', width: 80, title: 'ID', sort: true}
,{field: 'content', title: '图片', templet: '#uploadPicTpl', minWidth: 400}
,...
]]
,done: function (res) {
let tableId = this.id;
let tableElem = this.elem;
let tableViewElem = tableElem.next();
let uploadElem = tableViewElem.find('.upload-pic');
res.data.forEach((item) => {
upload.render({
url: '/index/upload/file'
,elem: uploadElem
,size: 10 * 1024
,done: function(res){
if (res.code == 100) {
} else {
}
}
});
});
}
});
});
exports('user', {});
});
|