附件 Attachment
Constructor
Implements: Widget
Tutorials: 控件对象使用快速入门
可设置的属性
Name | Type | Description |
---|---|---|
name | String | 控件的名字,唯一标志 |
title | String | 控件title |
hidden | Boolean | 隐藏 |
value | String | 值 |
readonly | Boolean | 只读 |
validates | Validators | 校验器 |
url | String | 上传页URL |
includeExts | Array|String | 后缀名白名单 |
excludeExts | Array|String | 后缀名黑名单 |
includeMsg | String | 白名单提示语 |
excludeMsg | String | 黑名单提示语 |
minSize | Number|String | 最小字节数 |
maxSize | Number|String | 最大字节数 |
customUploader | Boolean | 启用自定义上传页 |
cUrl | String | 自定义上传页地址 |
cWidth | Number | 自定义上传页宽 |
cHeight | Number | 自定义上传页高 |
hoverTip | String | 悬停提示 |
openUploader | String | 上传窗口标题 |
可获取的属性
Name | Type | Description |
---|---|---|
name | String | 控件的名字,唯一标志 |
title | String | 控件title |
hidden | Boolean | 隐藏 |
value | String | 值 |
readonly | Boolean | 只读 |
validates | Validators | 校验器 |
url | String | 上传页URL |
includeExts | Array|String | 后缀名白名单 |
excludeExts | Array|String | 后缀名黑名单 |
includeMsg | String | 白名单提示语 |
excludeMsg | String | 黑名单提示语 |
minSize | Number|String | 最小字节数 |
maxSize | Number|String | 最大字节数 |
customUploader | Boolean | 启用自定义上传页 |
cUrl | String | 自定义上传页地址 |
cWidth | Number | 自定义上传页宽 |
cHeight | Number | 自定义上传页高 |
hoverTip | String | 悬停提示 |
openUploader | String | 上传窗口标题 |
方法
validate
Description: 执行校验
返回值: Boolean 校验是否成功
调用举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
var result = widget.doMethod('validate');
intoView
Description: 把控件移动到页面可视范围
调用举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.doMethod('intoView');
addValidator
Description: 增加校验器
调用参数
Name | Type | Description |
---|---|---|
validator | Object | 校验器对象 |
返回值: 无
调用举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
//通过api增加必填校验器
widget.doMethod('addValidator' , vjsp.Validators.get(
'required',
[],
widgetLang.validate.required
));
removeValidator
Description: 删除校验器
调用参数
Name | Type | Description |
---|---|---|
name | String | 校验器名称 |
返回值: 无
调用举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
//删除必填校验
widget.doMethod('removeValidator' , 'required');
showValidateMsg
Description: 显示校验信息,多用于自定义校验器的开发
调用参数
Name | Type | Description |
---|---|---|
msg | String | 提示信息 |
返回值: 无
调用举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
//提示不能为空
widget.doMethod('showValidateMsg' , '控件不能为空');
hideValidateMsg
Description: 隐藏校验信息,多用于自定义校验器的开发
调用举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.doMethod('hideValidateMsg');
openUploader
Description: 打开上传窗口
调用举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.doMethod('openUploader');
download
Description: 下载
调用举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.doMethod('download');
事件
change
Description: 值改变
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('change' , function(){
//控制台输出新值
console.info('new value' , this.get('value'));
});
uploadSuccess
Description: 上传成功
回调函数参数
Name | Type | Description |
---|---|---|
resData | Object | 成功返回数据 |
返回值: 无
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('uploadSuccess' , function(resData){
//控制台输出
console.info('上传成功' , resData);
});
uploadBeforeSend
Description: 每次请求前
回调函数参数
Name | Type | Description |
---|---|---|
file | Object | 文件对象(只读) |
data | Object | 提交数据 |
header | Object | 请求头 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('uploadBeforeSend' , function(file , data , header){
//增加名为exval的提交数据
data.exval = 'uploadBeforeSend';
});
openUploader
Description: 打开附件上传窗口
回调函数参数
Name | Type | Description |
---|---|---|
formData | Object | 提交数据 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('openUploader' , function(formData){
//增加名为exval的提交数据
formData.exval = 'openUploader';
});
fileurl
Description: 此事件在使用附件地址时触发(预览/下载),可以在不改变控件值得情况下改变附件地址
回调函数参数
Name | Type | Description |
---|---|---|
fileurl | Object | 原始地址 |
返回值: String this.returnValue='新地址'
可以改变文件地址
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('fileurl' , function(formData){
//更改文件地址的域名
this.returnValue = fileurl.replace('xxx.online' , 'xxx.cn');
});
click
Description: 单击
回调函数参数
Name | Type | Description |
---|---|---|
e | Object | jQuery事件对象 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('click' , function(e){
vjsp.alert('click event');
});
dblclick
Description: 双击
回调函数参数
Name | Type | Description |
---|---|---|
e | Object | jQuery事件对象 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('dblclick' , function(e){
vjsp.alert('dblclick event');
});
contextmenu
Description: 弹出上下文菜单
回调函数参数
Name | Type | Description |
---|---|---|
e | Object | jQuery事件对象 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('contextmenu' , function(e){
vjsp.alert('contextmenu event');
});
mousedown
Description: 鼠标按下
回调函数参数
Name | Type | Description |
---|---|---|
e | Object | jQuery事件对象 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('mousedown' , function(e){
vjsp.alert('mousedown event');
});
mouseup
Description: 鼠标弹起
回调函数参数
Name | Type | Description |
---|---|---|
e | Object | jQuery事件对象 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('mouseup' , function(e){
vjsp.alert('mouseup event');
});
mousemove
Description: 鼠标移动
回调函数参数
Name | Type | Description |
---|---|---|
e | Object | jQuery事件对象 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('mousemove' , function(e){
vjsp.alert('mousemove event');
});
mouseover
Description: 鼠标移动控件上
回调函数参数
Name | Type | Description |
---|---|---|
e | Object | jQuery事件对象 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('mouseover' , function(e){
vjsp.alert('mouseover event');
});
mouseout
Description: 鼠标离开
回调函数参数
Name | Type | Description |
---|---|---|
e | Object | jQuery事件对象 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('mouseout' , function(e){
vjsp.alert('mouseout event');
});
mouseenter
Description: 鼠标移入
回调函数参数
Name | Type | Description |
---|---|---|
e | Object | jQuery事件对象 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('mouseenter' , function(e){
vjsp.alert('mouseenter event');
});
mouseleave
Description: 鼠标移出
回调函数参数
Name | Type | Description |
---|---|---|
e | Object | jQuery事件对象 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('mouseleave' , function(e){
vjsp.alert('mouseleave event');
});
keypress
Description: 按键按下并弹起
回调函数参数
Name | Type | Description |
---|---|---|
e | Object | jQuery事件对象 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('keypress' , function(e){
vjsp.alert('keypress event');
});
keydown
Description: 按键按下
回调函数参数
Name | Type | Description |
---|---|---|
e | Object | jQuery事件对象 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('keydown' , function(e){
vjsp.alert('keydown event');
});
keyup
Description: 按键弹起
回调函数参数
Name | Type | Description |
---|---|---|
e | Object | jQuery事件对象 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('keyup' , function(e){
vjsp.alert('keyup event');
});
blur
Description: 失去焦点
回调函数参数
Name | Type | Description |
---|---|---|
e | Object | jQuery事件对象 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('blur' , function(e){
vjsp.alert('blur event');
});
focus
Description: 获得焦点
回调函数参数
Name | Type | Description |
---|---|---|
e | Object | jQuery事件对象 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('focus' , function(e){
vjsp.alert('focus event');
});
input
Description: 正在输入
回调函数参数
Name | Type | Description |
---|---|---|
e | Object | jQuery事件对象 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('input' , function(e){
vjsp.alert('input event');
});
hidden
Description: 隐藏事件(隐藏显示触发 回调参数为隐藏状态)
回调函数参数
Name | Type | Description |
---|---|---|
hiddenState | Boolean | 隐藏状态true 为隐藏、false 为取消隐藏 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('hidden' , function(hiddenState){
if(hiddenState){
vjsp.alert('控件被隐藏');
}else{
vjsp.alert('控件取消隐藏');
}
});
readonly
Description: 只读事件 (只读状态改变触发 回调参数为只读状态)
回调函数参数
Name | Type | Description |
---|---|---|
readonlyState | Boolean | 只读状态 true 为只读、false 为取消只读 |
绑定举例:
var widget = vjsp.Parser.getWidgetByName('attachment');
widget.on('readonly' , function(readonlyState){
if(readonlyState){
vjsp.alert('控件只读');
}else{
vjsp.alert('控件取消只读');
}
});