layui中upload.render怎样动态设置里面的data参数值(reqID)

//初始化参数
var reqID;

//文件上传
    layui.use('upload', function() {
        //多文件列表示例
        var demoListView = $('#demoList');
        var indexInfo;
        upload.render({
            elem: '#testList'
            , url: '/uploadFile'
            , accept: 'file'
            , data: {"reqID":reqID,"busType":15}   //可放扩展数据  key-value
            , multiple: true
            , auto: false
            , bindAction: '#testListAction'
            , choose: function (obj) {
                if(!$.trim(reqID)){
                    parent.parent.parent.layer.msg("请先选择元件!", {time: 2000});
                }else{
                    var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                    //读取本地文件
                    obj.preview(function (index, file, result) {
                        var tr = $([''
                            , '' + file.name + ''
                            , '' + (file.size / 1014).toFixed(1) + 'kb'
                            , ''
                            , ''
                            , ''
                            , ''].join(''));
 
                        //删除
                        tr.find('.demo-delete').on('click', function () {
                            delete files[index]; //删除对应的文件
                            tr.remove();
                            uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值,以免删除后出现同名文件不可选
                        });
                        demoListView.append(tr);
                    });
                }
            }
            ,before: function(obj){

        if($('#demoList').children("tr").length > 0){

                     //预读本地文件示例,不支持ie8
                     indexInfo = parent.parent.showLoad();
                     this.data.reqID = reqID;

                }
            }
            ,allDone: function(obj){ //当文件全部被提交后,才触发
                parent.parent.closeLoad(indexInfo);
                indexInfo = '';
                parent.parent.parent.layer.msg("操作成功!", {time: 2000},function(){
                    doAttQuery();
                });
            }
            , done: function (res, index, upload) {
                //上传成功
                if (res.success) {
                    var tr = demoListView.find('tr#upload-' + index);
                    tr.remove();
                    return delete this.files[index]; //删除文件队列已经上传成功的文件
                }else{
                    parent.parent.parent.layer.msg(res.msg)
                }
            }
            , error: function (index, upload) {
                //后台只能传回json格式数据,不然会走error函数;
                parent.parent.closeLoad(indexInfo);
                indexInfo = '';
            }
        });
 
    });

你可能感兴趣的:(layui中upload.render怎样动态设置里面的data参数值(reqID))