Layui 文件上传 附带data数据

 

 

配置项中增加参数:

                    , data: {
                        CaseId: function () {
                            return $("#CaseId option:selected").val();
                        },
                        CaseName: function () {
                            return $("#CaseId option:selected").text();
                        }
                    }

 

 

例子:

                upload.render({
                    elem: ‘#test-upload-more‘
                    , url: ‘/Handler/CoverModelFileHandler.ashx?type=uploadAndCreate‘
                    , multiple: true
                    , accept: ‘file‘ //普通文件
                    , auto: false
                    , data: {
                        CaseId: function () {
                            return $("#CaseId option:selected").val();
                        },
                        CaseName: function () {
                            return $("#CaseId option:selected").text();
                        }
                    }
                    , choose: function (obj) {  //上传前选择回调方法
                        obj.preview(function (index, file, result) {

                            if ($("#CaseId option:selected").val() == ‘‘) {
                                $("#btnSubmit").click();
                                $(‘.layui-upload-file‘)[0].value = ‘‘;//解决两次选择的文件相同不能上传的问题
                                return false;
                            }

                            obj.upload(index, file);
                            return true;
                        });
                    }
                    , done: function (res, index, upload) {
                        $("#test-upload-more-list").append(‘<p>‘ + res.Name + ‘</p>‘);
                    }
                    , allDone: function (res) {
                        layer.msg(‘成功!‘, { icon: 1 });
                        parent.showCoverModelFile();
                    }
                });

 

文章来自:https://www.cnblogs.com/guxingy/p/12020497.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3