2010-12-01 68 views
1

我正在做一个PHP/ExtJS框架,它在第一页访问时生成基本的ExtJS Javascript,然后通过AJAX调用操纵​​DOM。用新的ExtJS元素替换ExtJS生成的DOM元素的最佳方式是什么?

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

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

但是,renderTo仅添加到该元素,而applyTo完全替换阻止我添加内容的内容,例如,因为第二个替代了第一个。

如何轻松操作ExtJS生成的Javascript,以便我可以用新内容替换屏幕区域,例如,在一个菜单中点击面板并将center_region替换为新内容?延长Ext.Container(Ext.Panel含税)

<!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> 

回答

1

类都添加,您可以用它来去除它们添加新的组件,以及删除()()方法。

+0

但我如何访问和操作现有组件? http://stackoverflow.com/questions/4325990/how-can-i-access-other-extjs-objects-from-within-extjs-click-events – 2010-12-01 15:43:51

0

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