|

楼主 |
发表于 2017-1-18 09:33:44
|
显示全部楼层
直接在system/components/justepattachment/demo/demoSimple.w中添加model1Load方法:
Model.prototype.model1Load = function(event){
var data = this.comp("data1");//attachmentSimple所绑定的data组件对象
var uploader = this.comp("attachmentSimple1").uploader;
$(uploader.inputElement).attr('multiple', 'multiple');//设置uploader中的multiple属性值,可以上传多张图片
//判断只要特定的文件类型可以上传
uploader.on('onFileSelected',function(event){
var fileType = event.file.type;
console.log("fileType=" + fileType);
//自己判断fileType,如果不符合条件用cancel为true终止选择文件
if(fileType != "image/jpeg" && fileType != "image/png" && fileType != "image/gif"){
event.cancel = true;
justep.Util.hint("请上传图片!");
}
//限制大小
console.log("fileSize=" + event.file.size);
if (event.file.size > 102400) {
justep.Util.hint("上传的文件大小不能超过100KB");
event.cancel = true;
return;
}
//限制长度fFile 为attachmentSimple绑定的字段
console.log("fId=" + data.getValue("fId") + ", fAttachment=" + data.getValue("fAttachment")); // 输出fId=0, fAttachment=undefined!!!
if ($.parseJSON(data.getValue("fAttachment")).length >= 1) {
alert("只能上传1个文件");
event.cancel = true;
return;
}
});
};
发现data.getValue("fAttachment")输出还是undefined! |
|