2010-12-01 29 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.通過使用這樣你的面板將被追加。

相關問題