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

Ext里的TreePanel使用TreeLoader加载子节点,txt和asp有区别吗?
初遇ExtJS,使用3.3.1版本,以下代码:

JScript code
Ext.onReady(function () {
    var tree = {
        xtype : 'treepanel',
        autoScroll : true,
        loader : new Ext.tree.TreeLoader({
            url : 'http://localhost/ext/data.txt'
        }),
        root : new Ext.tree.AsyncTreeNode({
            text : 'My Company',
            id : 'myCompany',
            expanded : true
        })
    }

    new Ext.Window({
        height : 300,
        width : 300,
        layout : 'fit',
        border : false,
        title : 'Our first remote tree',
        items : tree
    }).show();
});



当上述代码中:
JScript code
loader : new Ext.tree.TreeLoader({
    url : 'http://localhost/ext/data.txt'
})


url路径文件扩展名为txt或htm时,页面上无法显示树的子节点,
而当同样的URL只是将data.txt改成data.asp,树的子节点就能显示出来

请教这是什么原因?
data.txt和data.asp部署在IIS上,内容一样,如下:

JScript code
[
    {
        text: 'not a leaf'
    },
    {
        text: 'is leaf',
        leaf: true
    }
]


------解决方案--------------------
这个是因为静态页面,html,txt默认IIS只支持get请求,不支持post请求,你的这个问题和这个问题差不多

jquery easyui datagrid数据源为json文件问题

而ext默认请求是以post发出的,所以出现了405 Method Not Allowed错误,所以无法加载数据

将ext的请求方法改为get,或者配置iis允许html,txt文件支持post请求

JScript code
        Ext.onReady(function () {
            var tree = {
                xtype: 'treepanel',
                autoScroll: true,
                loader: new Ext.tree.TreeLoader({
                    url: 'data.txt'
                    , requestMethod: 'get'//////////
                }),
                root: new Ext.tree.AsyncTreeNode({
                    text: 'My Company',
                    id: 'myCompany',
                    expanded: true
                })
            }

            new Ext.Window({
                height: 300,
                width: 300,
                layout: 'fit',
                border: false,
                title: 'Our first remote tree',
                items: tree
            }).show();
        });