代码之家  ›  专栏  ›  技术社区  ›  Eugene

使用extjs在其他窗口中的事件上更新一个窗口的内容

  •  1
  • Eugene  · 技术社区  · 16 年前

    不久前我开始学习extjs库,现在我想创建以下内容:

    有一个浏览器窗口,它是垂直分隔的。
    在左边有一个目录和子目录的树面板(只有2层深)。
    在右侧,将为所选子目录的内容提供一个输出。

    我已经完成了界面部分,但我不知道当用户单击左侧的子目录时如何更改右侧的内容。我可以使用ext.ajax.request进行请求,但是我不知道如何触发右侧内容的更新。

    顺便说一句。正如我所说,左侧是树面板,右侧是夹持面板,它们在xType为“panel”的视区中,但我认为这不适合这个问题。

    有什么建议吗?

    1 回复  |  直到 16 年前
        1
  •  1
  •   SW4    16 年前

    首先,您需要注册用户在树面板中选择节点的事实,这可以通过以下方式完成:

    yourtreepanel.getSelectionModel().on('selectionchange', whattodonext);
    

    其中“your treepanel”是treepanel的名称(如果treepanel被分配给变量,则使用ext.getcmp(“your treepanel”).getselecti….),“whattodonext”是用户选择节点时要调用的函数的名称。

    函数“whattodonext”如下所示:

        function whattodonext(){
            node=yourtreepanel.selModel.selNode;
            if(node){
                if(node.isLeaf()){
    // this works out what you want to do if the user has selected a valid leaf node
    
    
                }else{
    // otherwise...put anything you wish to happen here (i.e. if a folder has been selected)
    
                }
    
            }   
        }
    

    下一部分是用内容(如果它被称为“MyContentpanel”)将面板更新到右侧。假设此内容应该从“mycontent.html”中加载,该部分包含

    // this works out what you want to do if the user has selected a valid leaf node
    

    你可以把代码:

    mycontentpanel.load({
    url: 'mycontent.html',
    params: {
    yourparam1:'param1value',
    yourparam2:'param2value'
    },
    nocache: true,
    timeout: 30
    });
    

    就是这样!

    您可以使用参数选项发送您可能拥有的任何特定的日志参数,这些参数将决定服务的内容。

    别忘了,如果遇到困难,请尝试使用ext.getcmp(“objectname”)引用对象,而不仅仅是“objectname”。操作….

    祝你好运!