[英]Getting error as : Uncaught TypeError: Cannot read property 'parentNode' of null
I am trying to add new div adjacent to one div with the reference of ComponentID of the first div I want to add the second parallel div Like: 我正在尝试使用第一个div的ComponentID的引用添加与一个div相邻的新div,我想添加第二个并行div,例如:
<div>
<div id="userActivityStatusMenu-1110">Neighbor 1</div>
// want new div here
</div>
Below is the script I am trying: 以下是我正在尝试的脚本:
/* Adds Element BEFORE NeighborElement */
Element.prototype.appendBefore = function (element) {
element.parentNode.insertBefore(this, element);
}, false;
/* Adds Element AFTER NeighborElement */
Element.prototype.appendAfter = function (element) {
element.parentNode.insertBefore(this, element.nextSibling);
}, false;
/* Typical Creation and Setup A New Orphaned Element Object */
var NewElement = document.createElement('div');
NewElement.innerHTML = 'This is new element';
NewElement.id = 'NewElement';
/* Add NewElement BEFORE -OR- AFTER Using the Aforementioned Prototypes */
NewElement.appendAfter(getComponent(Ext.getCmp("userActivityStatusMenu-1110").itemId));
Please let me know where I am doing wrong,or what is the best way to do this 请让我知道我做错了什么,或者做这件事的最佳方法是什么
To get the DOM Node of any ExtJS Component, you can either pass the component itself or the id of the component to Ext.getDom(idOrComponent) 要获取任何ExtJS组件的DOM节点,您可以将组件本身或该组件的ID传递给Ext.getDom(idOrComponent)
Example: NewElement.appendAfter(Ext.getDom("userActivityStatusMenu-1110")); 示例:NewElement.appendAfter(Ext.getDom(“ userActivityStatusMenu-1110”));;
Note : It's not recommended to work with the id field at all. 注意 :完全不建议使用id字段。 Instead assign a custom, unique itemId and query the Component via
Ext.ComponentQuery.query('#itemid')
instead. 而是分配一个自定义的唯一itemId,然后通过
Ext.ComponentQuery.query('#itemid')
查询组件。
Note2 : To be completely in line with the style of ExtJS, you should not manipulate the internal HTML structure at all. 注意2 :要完全符合ExtJS的样式,您完全不应操纵内部HTML结构。 Instead either add new items to the parent element or if you really need custom HTML to be inserted, modify the html property or XTemplate of whatever Component you're trying to modify here.
而是将新项目添加到父元素,或者如果您确实需要插入自定义HTML,请修改您在此处尝试修改的任何组件的html属性或XTemplate。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.