1

我使用 ExtJS 4.2。我想在浏览文件时更改文件字段的值。这样做的原因是删除“C:\fakepath”字符串。任何帮助表示赞赏。

4

2 回答 2

2

C:\fakepath来自浏览器,因此您看不到真实路径,但可以隐藏路径并仅显示文件名。您可以通过扩展文件字段来做到这一点:

Ext.define('Ext.form.field.ExtFile', {
    extend: 'Ext.form.field.File',

    onFileChange: function(button, e, value) {
        var newValue = value.replace(/^c:\\fakepath\\/i, ''); // remove fakepath

        return this.callParent([ button, e, newValue ]);
    }
});

工作样本:http: //jsfiddle.net/Qppjc/1/

于 2013-10-31T07:34:56.560 回答
0

我发现最好的方法是覆盖该字段。

这是 ExtJs 4 和 5 的解决方案(在 ExtJs 6 上也适用于我):http ://code.tonytuan.org/2014/10/extjs-get-rid-of-fake-path-in-file-字段.html

Ext.define('Ext.enhance.form.field.File', {
    override: 'Ext.form.field.File',     
    onFileChange: function(button, e, value) {
        this.duringFileSelect = true;
        Ext.form.field.File.superclass.setValue.call(this, value.replace(/^.*(\\|\/|\:)/, ''));
        delete this.duringFileSelect;
    }   
});
于 2017-09-12T12:37:53.240 回答