extjs - extjs:模态对话框html dom准备好后调用函数
问题描述
我有一个要求,在单击按钮时我必须带来一个 extjs 模态对话框,并且在模态对话框中的 html 准备好后,我想捕获对话框的 html 内容中存在的 DOM 元素。下面是html内容:
<html>
<head>
<link rel="stylesheet" type="text/css" href="<path to extjs installation folder>\extjs\resources\css\ext-all.css"/>
<script type="text/javascript" src="<path to extjs installation folder>\extjs\adapter\ext\ext-base.js"></script>
<script type="text/javascript" src="<path to extjs installation folder>\extjs\ext-all.js"></script>
<script>
Ext.onReady(function(){
var button = Ext.get('modal-btn');
button.on('click', showModal);
});
var showModal = function(){
var win;
if(!win){
win = new Ext.Window({
modal:true,
layout:'fit',
width:500,
height:300,
closeAction:'hide',
plain: true,
items: new Ext.Panel({
frame:true,
collapsible:true,
items:[{
html:'<object id="renderedObjId" width=760 height=350></object>'
}]
}),
buttons: [{
text: 'Close',
handler: function(){
win.hide();
}
}]
});
}
win.show(this);
}
</script>
</head>
<body>
<form name="modalDialogForm">
<input type="button" id="modal-btn" value="Click"/><br /><br />
</form>
</body>
</html>
我想捕获使用renderObjId表示的模态对话框的 html 内容中存在的对象。我没有更新这个 html 的内容。任何建议都会非常有帮助。
解决方案
所以你想获取html内容。您可以使用afterrender
事件Ext.panel.Panel
并在处理程序中获取您的元素。在FIDDLE中有两种方式。
items: new Ext.Panel({
frame: true,
collapsible: true,
items: [{
html: '<object id="renderedObjId" width=760 height=350></object>'
}],
listeners: {
afterrender: function (cmp) {
var htmlOb;
// #1
htmlOb = document.getElementById('renderedObjId');
console.log(htmlOb.innerHTML);
console.log(htmlOb.innerText);
console.log(htmlOb.textContent);
// #2
htmlOb = Ext.get('renderedObjId').dom;
console.log(htmlOb.innerHTML);
console.log(htmlOb.innerText);
console.log(htmlOb.textContent);
}
}
}),
推荐阅读
- c++ - 我想制作彼此不同但重复的数字的数字
- python-3.x - 如何使用单个按钮开始和停止录制
- flutter - 在 initState 中访问 InheritedWidget 数据
- html2canvas - html2canvas 每次生成不同的结果
- php - .htaccess 代码阻止所有直接访问,但允许通过 include / cron_jobs / ajax 请求进行内部访问
- arrays - excel VBA中的数据验证列表
- python - Pandas:创建带有产品列表组的表格
- python - 从 csv 中透视数据并存储在数据框中
- python - 仅替换模式中的第二次出现
- javascript - 检查 JavaScript 数组中的值范围