【发布时间】: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