简体   繁体   English

获取错误为:未捕获的TypeError:无法读取null的属性“ parentNode”

[英]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 请让我知道我做错了什么,或者做这件事的最佳方法是什么

  1. getComponent is not a global function, but a method of every ExtJS Container getComponent不是全局函数,而是每个ExtJS容器的方法
  2. someContainer.getComponent will not return a DOMElement, but an Ext.Component or one of its descendants someContainer.getComponent将不返回DOMElement,而是Ext.Component或其后代之一

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.

相关问题 未捕获的TypeError:无法读取null javascript的属性“ parentNode” - Uncaught TypeError: Cannot read property 'parentNode' of null javascript 未捕获的TypeError:无法读取未定义的属性&#39;parentNode&#39; - Uncaught TypeError: Cannot read property 'parentNode' of undefined 未捕获的TypeError:无法读取未定义的属性“parentNode” - Uncaught TypeError: Cannot read property 'parentNode' of undefined 未捕获的类型错误:无法读取null的属性“ parentNode” - Uncaught Type Error :Cannot read property 'parentNode' of null 获取未捕获的类型错误:无法读取滚动的空错误的属性“offsetTop” - Getting Uncaught TypeError: Cannot read property 'offsetTop' of null error for scroll 得到此错误“未捕获的TypeError:无法读取null的属性&#39;documentElement&#39;” - getting this error “Uncaught TypeError: Cannot read property 'documentElement' of null” 151 Uncaught TypeError:删除第二个费用元素时,无法读取null的属性“ parentNode” - 151 Uncaught TypeError: Cannot read property 'parentNode' of null, when removing 2nd expense element Javascript 错误:无法读取 null 的属性“parentNode” - Javascript error: Cannot read property 'parentNode' of null 数据表:未捕获的TypeError:无法读取未定义的属性&#39;parentNode&#39; - Datatables: Uncaught TypeError: Cannot read property 'parentNode' of undefined 未捕获的TypeError:无法读取PHP脚本中未定义的属性“ parentNode” - Uncaught TypeError: Cannot read property 'parentNode' of undefined in php script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM