var data =["2020年","2019年","2018年","2017年","2016年"]
$('#type').html('<option value="">請選擇</option>');
$.each(data,function(k,v){
$('#type').append('<option value="'+ v+'">'+v+'</option>');
})
form.render('select');
//創建一個上傳組件
upload.render({
elem: '#import'
,url: getRootPath() +'db/policy/insertPolicy'
,data: {
type:'126',
parent:$('#type').val()
}
,auto:true
,accept: 'file' //普通文件
,done: function(res, index, upload){ //上傳後的回調
if(res.status == '1001'){
layer.msg(res.message);
}else if(data.status =="1003"){
layer.msg(data.message);
}
}
})
上面代碼的傳參方式,parent參數的值一直是null。後來又仔細看了layui 文件上傳的文檔。因爲我的select是動態渲染的,要用下面的寫法。
(layui2.2.6及其以上支持動態值)詳情見文檔