我想要使用extjs4.2
我在附件中使用此组件:
{
xtype: 'filefield',
id: 'file6',
fieldLabel: 'test ',
labelWidth: 100,
msgTarget: 'side',
allowBlank : false,
anchor: '100%',
buttonText: 'upload'
},我希望有一个附件组件,它显示没有文本的文件名:c /fakepath。
发布于 2014-03-10 15:10:05
但是,没有一个内置的方法来完成这一任务,您可以对fakepath进行查找/替换并删除。我在change事件中提出了这一点。下面是一个示例:
listeners: {
change: function(fld, value) {
var newValue = value.replace(/C:\\fakepath\\/g, '');
fld.setRawValue(newValue);
}
}我创建了一个森查小提琴,演示了一个工作示例
发布于 2015-07-23 14:50:17
类似于answer 3550464的答案,但在整个代码中却少了很多:
将其添加到文件字段侦听器对象中。此代码将删除字段中最后一个斜杠或反斜杠之前的所有文本,并将其包括在内。
change: function (field, value) {
'use strict';
var newValue = value.replace(/(^.*(\\|\/))?/, "");
field.setRawValue(newValue);
}发布于 2015-03-26 12:46:51
以下是基于weeksdev的答案的改进。将以下侦听器添加到您的文件字段:
/* remove the path (if any) so that only the file name is displayed
* note: to be consistent across browsers
* -- some of them give a fake path, some others give a file name
*/
change: function(fileField, value, eventOptions) {
var newValue;
var lastForwardSlash = value.lastIndexOf('\/');
/* if this is a Windows-based path or just a file name
* (Windows-based paths and file names in general don't contain forward slashes)
*/
if (lastForwardSlash < 0) {
/* remove the characters before the last backslash (included)
* but only for Windows users -- as UNIX-like file names may contain backslashes
*/
if (Ext.isWindows === true) {
newValue = value.substring(value.lastIndexOf('\\') + 1);
} else {
newValue = value;
}
}
// there is a forward slash: this is a UNIX-like (Linux, MacOS) path
else {
// remove the characters before the last forward slash (included)
newValue = value.substring(lastForwardSlash + 1);
}
fileField.setRawValue(newValue);
}https://stackoverflow.com/questions/22302841
复制相似问题