Javascript 带有extjs 4.2且不带伪路径的文件字段
我想要使用ExtJS4.2 我在附件中使用此组件:Javascript 带有extjs 4.2且不带伪路径的文件字段,javascript,extjs,Javascript,Extjs,我想要使用ExtJS4.2 我在附件中使用此组件: { xtype: 'filefield', id: 'file6', fieldLabel: 'test ', labelWidth: 100, msgTarget: 'side', allowBlank : false, anchor: '100%', buttonText: 'upload' }, 我希望有一个附件组件,该组件显示文件名,但
{
xtype: 'filefield',
id: 'file6',
fieldLabel: 'test ',
labelWidth: 100,
msgTarget: 'side',
allowBlank : false,
anchor: '100%',
buttonText: 'upload'
},
我希望有一个附件组件,该组件显示文件名,但不显示以下文本:
c/fakepath没有内置的方法来完成此操作,但是,您可以对fakepath执行查找/替换并删除。我在
change
事件中推动了这一点。以下是一个例子:
listeners: {
change: function(fld, value) {
var newValue = value.replace(/C:\\fakepath\\/g, '');
fld.setRawValue(newValue);
}
}
我创建了一个演示工作示例这里是基于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);
}
/*删除路径(如果有),以便只显示文件名
*注意:要在不同浏览器之间保持一致
*--其中一些给出了一个假路径,另一些给出了一个文件名
*/
更改:函数(文件字段、值、事件选项){
var新值;
var lastForwardSlash=value.lastIndexOf('\/');
/*如果这是一个基于Windows的路径或只是一个文件名
*(基于Windows的路径和文件名通常不包含正斜杠)
*/
如果(lastForwardSlash<0){
/*删除最后一个反斜杠(包括)之前的字符
*但仅适用于Windows用户,因为类UNIX文件名可能包含反斜杠
*/
如果(Ext.isWindows===true){
newValue=value.substring(value.lastIndexOf('\\')+1);
}否则{
newValue=值;
}
}
//有一个正斜杠:这是一个类UNIX(Linux、MacOS)路径
否则{
//删除最后一个正斜杠前的字符(包括)
newValue=value.substring(lastForwardSlash+1);
}
fileField.setRawValue(newValue);
}
与user3550464的答案类似,但代码要少得多:
将其添加到文件字段侦听器对象。
此代码将删除字段中最后一个斜杠或反斜杠之前的所有文本
change: function (field, value) {
'use strict';
var newValue = value.replace(/(^.*(\\|\/))?/, "");
field.setRawValue(newValue);
}
你不能,没有一些黑客。请参阅此重复线程:这在InternetExplorer11中不起作用。它粘贴在实际路径中,而不是伪路径