我是个新手。
这个是表格生成的代码:
var initFileList = function (){
Ext.QuickTips.init();
var fm = Ext.form;
var cm = new Ext.grid.ColumnModel([
{header: '文件名', dataIndex: 'name' ,width: 200, sortable: true, editor: new fm.TextField({allowBlank: false})},
{header: '大小', dataIndex: 'size' , sortable: true},
{header: '管理', dataIndex: 'url'}
]);
var ds = new Ext.data.JsonStore({
url: 'fileAction.do?command=list&type=list&projectId=${projectId }',
autoLoad:true,
root: 'files',
fields: ['name','size', 'url'],
});
//var data = [];
//var ds = new Ext.data.Store({
//proxy: new Ext.data.MemoryProxy(data),
//reader: new Ext.data.ArrayReader({},[
//{name: 'name', mapping: 0},
//{name: 'size', mapping: 1},
//{name: 'manage', mapping: 2}
//])
//});
var grid = new Ext.grid.EditorGridPanel({
el: 'fileList',
store: ds,
ds: ds,
cm: cm,
title:'项目文件浏览',
selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
clicksToEdit:2,
autoHeight: true,
tbar: [
action
]
});
grid.on("afteredit",afterEdit,grid);
//ds.load();
grid.render();
}
这是页面实用的代码:
Ext.onReady(function(){
initFileList();
});
这是Action中的代码:
List<File> projectFiles = getProjectFiles(rootFile, fileForm.getProjectId());
JSONArray array = new JSONArray();
for(File f:projectFiles){
JSONObject obj = new JSONObject();
obj.put("name", f.getName());
obj.put("size", f.length());
obj.put("url", mime.encoder(f.getName().getBytes()));
array.put(obj);
}
JSONObject obj = new JSONObject();
obj.put("files", array);
response.getWriter().println(obj);