发表于: 2017-04-20 20:33:33
2 1492
今天完成的事情:完成新建目录功能
明天计划的事情:项目不忙的话,提交任务一
遇到的问题: 思路上想难了,其实就是create一个folder,难点就是取到要建立文件夹的路径,就要到extjs的API里去查,发现grid下有个title属性,grid.title搞定。
/*
* 新建目录按钮
*/
var createFolderButton = Ext.create('Ext.button.Button',{
cls:'mybutton',
text:'<span style="font-size:13px; font-weight:normal">新建目录</span>',
margin: '0 0 0 70',// (top, right, bottom, left)
scope:this,
handler: function(record) {
var grid = this.grid;
Ext.Msg.prompt('输入框', '新建目录名称:', function(btn, text) {
if (btn == 'ok') {
if (text == '') {
alert("命名不能为空!");
} else {
var path = grid.title;// 拿到title 后台拼接成路径
var folderName = text;
Ext.Ajax.request({
url: getRootPath()+"/statisticalYearbook/createFolderSYBAction.action?downPath=" + path + "&folderName=" + folderName,
params: {downPath: path, folderName: folderName},
async: true,
method: 'POST',
success: function(response) {
var store = Ext.data.StoreManager.lookup('simpsonsStore');
store.load();
},
failure: function(response) {
alert("文件夹已经存在");
}
});
}
}
});
}
});
后台代码:
// 创建目录
public void createFolder() {
HttpServletRequest request = ServletActionContext.getRequest();
String path = request.getParameter("downPath");
String folderName = request.getParameter("folderName");
if(path.equals("统计年鉴") || path.equals("") ) {
path = rootPath;
} else {
path = path.substring(path.indexOf("-")).replace("-", "");
path = rootPath + "//" + path;
}
path += "//" + folderName;
String filePath = path.replaceAll("//", "\\\\");
boolean rtur = SYBFileIO.folderCreate(filePath);
this.sendJSONWeb("{success:" + rtur + ")}");
}
// 建立文件夹
public static boolean folderCreate(String path) {
File file = new File(path);
if (file.exists()) {
return false;
} else {
file.mkdirs();
return true;
}
}
收获: 多试试ApI里的方法会有惊喜。编程的API大多都是英文,不好理解,可以结合百度加深理解
评论