【问题标题】:What is the best way to replace ExtJS-generated DOM elements with new ExtJS elements?用新的 ExtJS 元素替换 ExtJS 生成的 DOM 元素的最佳方法是什么?
【发布时间】:2014-03-27 16:47:09
【问题描述】:

我正在制作一个 PHP/ExtJS 框架,它在第一次访问页面时生成基本的 ExtJS Javascript,然后通过 AJAX 调用操作 DOM。

所以我需要能够用 ExtJS 创建的新 DOM 元素替换 ExtJS 创建的特定 DOM 元素。

在下面的示例中,我想用两个面板替换 region_center 中的文本。

但是,renderTo 仅添加到元素中,而 applyTo 完全替换了内容,这使我无法添加例如2 个面板,因为第二个面板取代了第一个面板。

如何轻松操作 ExtJS 生成的 Javascript,以便我可以用新内容替换屏幕区域,例如在单击面板和 center_region 被新内容替换的菜单中?

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css">
        <script type="text/javascript" src="ext/adapter/ext/ext-base.js">
        </script>
        <script type="text/javascript" src="ext/ext-all-debug.js">
        </script>
        <script type="text/javascript" src="js/jquery-1.4.4.min.js">
        </script>
        <title>Test of RenderTo</title>
        <script type="text/javascript">
            Ext.onReady(function(){
                new Ext.Panel({
                    id: 'new_content1',
                    renderTo: 'region_center',
                    title: 'the title',
                    margins: '10 10 10 10',
                    html: 'content1 added by extjs'
                });
                new Ext.Panel({
                    id: 'new_content2',
                    renderTo: 'region_center',
                    title: 'the title',
                    margins: '10 10 10 10',
                    html: 'content2 added by extjs'
                });
            });
        </script>
    </head>
    <body>
        <h1 class="main">Test of renderTo:</h1>
        <div id="region_center" class=" x-panel x-border-panel" style="left: 220px; top: 43px; width: 1478px;">
            <div class="x-panel-bwrap" id="ext-gen9">
                <div class="x-panel-body x-panel-body-noheader" id="ext-gen10" style="padding: 10px; overflow: auto; width: 1456px; height: 620px;">
                    this is the original text and should be replaced
                </div>
            </div>
        </div>
    </body></html>

【问题讨论】:

    标签: extjs


    【解决方案1】:

    所有扩展 Ext.Container 的类(包括 Ext.Panel)都有 add() 方法,您可以使用该方法添加新组件,以及 remove() 用于删除它们。

    【讨论】:

    【解决方案2】:

    我看到在您的代码中,您使用了renderTo 'region_center'。我希望region_center 应该是div。尝试包含renderTo: Ext.getBody()renderTo: document.body. 通过使用这样您的面板将被附加。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多