首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用没有fakepath的extjs4.2的Filefield

使用没有fakepath的extjs4.2的Filefield
EN

Stack Overflow用户
提问于 2014-03-10 14:24:18
回答 3查看 8.2K关注 0票数 4

我想要使用extjs4.2

我在附件中使用此组件:

代码语言:javascript
复制
{
    xtype: 'filefield',
    id: 'file6',
    fieldLabel: 'test ',
    labelWidth: 100,
    msgTarget: 'side',                  
    allowBlank : false,
    anchor: '100%',
    buttonText: 'upload'
},

我希望有一个附件组件,它显示没有文本的文件名:c /fakepath

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-03-10 15:10:05

但是,没有一个内置的方法来完成这一任务,您可以对fakepath进行查找/替换并删除。我在change事件中提出了这一点。下面是一个示例:

代码语言:javascript
复制
listeners: {
                        change: function(fld, value) {
                            var newValue = value.replace(/C:\\fakepath\\/g, '');
                            fld.setRawValue(newValue);
                        }
                    }

我创建了一个森查小提琴,演示了一个工作示例

票数 10
EN

Stack Overflow用户

发布于 2015-07-23 14:50:17

类似于answer 3550464的答案,但在整个代码中却少了很多:

将其添加到文件字段侦听器对象中。此代码将删除字段中最后一个斜杠或反斜杠之前的所有文本,并将其包括在内。

代码语言:javascript
复制
change: function (field, value) {
    'use strict';
    var newValue = value.replace(/(^.*(\\|\/))?/, "");
    field.setRawValue(newValue);
}
票数 3
EN

Stack Overflow用户

发布于 2015-03-26 12:46:51

以下是基于weeksdev的答案的改进。将以下侦听器添加到您的文件字段:

代码语言:javascript
复制
/* 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);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22302841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档