好的,我有这个网站,我把它放在游戏框架中。它基本上连接到后端的 FTP 站点,检索文件夹/文件列表并将其作为 JSON 发送到基本的 ExtJS 前端。
我让它工作,以便正确填充树面板,但是当我展开非叶节点时,它似乎没有做任何特别的事情。
根据我读过的内容,它应该使用数据 url,并将带有节点 id 的节点参数传递给该数据 url 以获取子节点的数据,但在 firebug 中我没有看到任何请求发送该数据。
我需要做什么来允许 ajax 调用触发,以便具有子节点的节点在节点展开时动态获取它们?
以下是相关代码供参考:
Ext.onReady(function() {
new Ext.Viewport({
layout: 'border',
defaults: {
height: 100,
width: 250,
collapseMode: 'mini'
},
items : [
{
region: 'center',
margins: '5 5 0 0',
contentEl: 'center-content'
},
{
id: 'file-tree',
region: 'west',
title: 'Files',
split: true,
collapsible: true,
xtype: 'treepanel',
autoScroll: true,
loader: new Ext.tree.TreeLoader({
dataUrl: 'http://localhost:9000/application/listFiles',
}),
root: new Ext.tree.AsyncTreeNode({
expand: true,
text: "/",
id: "/"
}),
rootVisibile: true,
listeners: {
click: function(n) {
Ext.Msg.alert('File Tree Click', 'You clicked: ' + n.attributes.id);
}
}
}
]
});
});
JSON 中返回的 id 是我想要展开的子目录的完整路径,并且 listfiles 操作将采用该参数并返回适当的文件。
根据要求,这是 JSON 输出的片段:
[
{
id: "/./",
text: "./",
leaf: false,
children: [ ]
},
{
id: "/../",
text: "../",
leaf: false,
children: [ ]
},
{
id: "/.ftpquota",
text: ".ftpquota",
leaf: true,
children: [ ]
},
{
id: "/.htaccess",
text: ".htaccess",
leaf: true,
children: [ ]
},
{
id: "/022610.html",
text: "022610.html",
leaf: true,
children: [ ]
},
{
id: "/Gail/",
text: "Gail/",
leaf: false,
children: [ ]
}
]
最后一项是我希望将子项动态加载到的文件夹的示例。