日期:2014-05-16  浏览次数:20311 次

ExtJS 文件下载问题
在做的一个项目里面希望提供文件的上传于下载,下载的需求是选中GridPanel中的一行,点击下载,会弹出“另存为..”对话框供,用window.open()会提示报错,请问ExtJS的代码该怎么写。

DownloadExcelFiles = function(){
    var record = grid1.getSelectionModel().getSelections();//grid1为已定义的GridPanel
    if (record.length == 0) {
        Ext.MessageBox.alert('系统提示信息', '请选择你要下载的文件!');
    }
    else 
        if (record.length > 1) {
            Ext.MessageBox.alert('系统提示信息', '一次只能下载一个文件!')
        }
        else 
            if (record.length == 1) {
                var _filename = ' ';
var _filepath = 'E:\\work\\temp\\'; 
_filename = _filepath + record[0].get('name');
alert(_filename);
                window.open(_filename, '_blank', 
'width=1,height=1,toolbar=no,menubar=no,location=no');//报错,提示“拒绝访问”
            }
}


------解决方案--------------------
采用Ext.window的方法
var win = new top.Ext.Window({
    items : [{ html :_filename}]
});
win.show(); 
------解决方案--------------------

window.location.href = obj.path;//这样就可以弹出下载对话框了
跳转到一个普通的jsp或html页面,页面上提供下载地址或下载操作

------解决方案--------------------
 var _filepath = 'E:\\work\\temp\\'; 

这句应该写成服务端的虚拟路径