javascript 如何使 extjs 手风琴布局示例动态化?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4163973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 10:33:55  来源:igfitidea点击:

How to make the extjs accordion layout example dynamic?

javascriptextjs

提问by Edward Tanguay

I've pulled out the accordion layout .html and .js files from the extjs examples(below).

我已经从extjs 示例(如下)中提取了手风琴布局 .html 和 .js 文件。

What is the next stepto make this dynamic e.g. how the syntax of a link looks so that the HTML that fills a section under a panel on the left has links which fill the content on the right.

什么是下一个步骤,使这个充满活力例如,如何链接外观的语法,使填充在左侧面板下部分HTML有填补右边的内容链接。

Does anyone know of tutorials which go beyond this shell and show how to make it dynamic, i.e. integrate it in a working application?

有谁知道教程超出了这个 shell 并展示了如何使它动态化,即将它集成到一个工作应用程序中?

<html>
<head>
    <title>Accordion Layout</title>
    <link rel="stylesheet" type="text/css" href="resources/css/ext-all.css"/>

    <!-- GC -->
    <!-- LIBS -->
    <script type="text/javascript" src="adapter/ext/ext-base.js"></script>
    <!-- ENDLIBS -->

    <script type="text/javascript" src="ext-all.js"></script>

    <style type="text/css">
        html, body {
            font: normal 12px verdana;
            margin: 0;
            padding: 0;
            border: 0 none;
            overflow: hidden;
            height: 100%;
        }
        .empty .x-panel-body {
            padding-top:20px;
            text-align:center;
            font-style:italic;
            color: gray;
            font-size:11px;
        }
    </style>
    <script type="text/javascript">
        Ext.onReady(function() {

            var item1 = new Ext.Panel({
                title: 'Start',
                html: '&lt;this is the start content&gt;',
                cls:'empty'
            });

            var item2 = new Ext.Panel({
                title: 'Application',
                html: '&lt;empty panel&gt;',
                cls:'empty'
            });

            var item3 = new Ext.Panel({
                title: 'Module',
                html: '&lt;empty panel&gt;',
                cls:'empty'
            });



            var accordion = new Ext.Panel({
                region:'west',
                margins:'5 0 5 5',
                split:true,
                width: 210,
                layout:'accordion',
                items: [item1, item2, item3]
            });

            var viewport = new Ext.Viewport({
                layout:'border',
                items:[
                    accordion, {
                    region:'center',
                    margins:'5 5 5 0',
                    cls:'empty',
                    bodyStyle:'background:#f1f1f1',
                    html:'This is where the content goes for each selection.'
                }]
            });
        });
    </script>
</head>
<body>
<script type="text/javascript" src="../shared/examples.js"></script><!-- EXAMPLES -->
</body>
</html>

回答by Juan Mendes

There's a billion ways to do it. The question is vague... but here's a very simplistic one. Just have an Ajax function that calls the server and adds the panels dynamically. Say your server provides the following JSON, by calling /links.json

有十亿种方法可以做到。这个问题很模糊……但这是一个非常简单的问题。只需有一个调用服务器并动态添加面板的 Ajax 函数即可。假设您的服务器通过调用 /links.json 提供以下 JSON

{links: ['http://www.google.com'], ['http://www.yahoo.com']}

You would do the following

你会做以下事情

    Ext.onReady(function() {
        var accordion = new Ext.Panel({
            region:'west',
            margins:'5 0 5 5',
            split:true,
            width: 210,
            layout:'accordion'
        });

        new Ext.Viewport({
            layout:'border',
            items:[
              accordion, 
              {region:'center', html:'This is where the content goes for each selection.'}]
        });

        Ext.Ajax.request({
            url: '/links.json',
            callback: function(response) {
                var json = Ext.decode(response);
                var cfgs = [];
                for (var i = 0; i < json.links.length; i++) {
                    cfgs.push({
                        html: json.links[i]
                    })
                }
                accordion.add(cfgs);
            }
        });            
    });

But there's nothing that I coded here that you didn't already know, is there?

但是我在这里编写的任何代码你都不知道,是吗?

回答by Tommi

Here's a very good source of information that will probably help you get forward: Saki's Ext Examples Page.

这是一个非常好的信息来源,可能会帮助您前进: Saki 的 Ext 示例页面