attachmentSimple组件默认没有提供设置上传个数的控制,如果需要控制,可以获取到组件上的uploader,在uploader上绑定事件onFileSelected进行控制
获取uploader参考:
var attachmentSimple = this.comp("attachmentSimple3") var uploader = attachmentSimple.uploader;
给uploader绑定onFileSelected参考:
uploader.on('onFileSelected',function(event){ });
控制只能上传一个文件,再上传提示是否替换可以在model的onLoad事件中如下实现:
Model.prototype.modelLoad = function(event) { var attachmentSimple = this.comp("attachmentSimple3") var uploader = attachmentSimple.uploader; var data = this.comp("mainData"); uploader.on('onFileSelected', function(event) { var fFJ = data.getValue("fFJ"); var jsonList = eval("(" + fFJ + ")"); if (jsonList != undefined && jsonList.length > 0) {// 判断是否有文件 var storeFileName = jsonList[0]["storeFileName"]; var ownerID = jsonList[0]["ownerID"]; var r = confirm("只允许上传一个文件是否替换原有文件"); if (r == true) { attachmentSimple1.removeItemByStoreID(storeFileName, ownerID);// 删除原来的文件 } else { event.cancel = true; } } }); };
评一波