无法删除组件(试图删除不存在的组件)
Cannot remove components (Attempted to remove a component that does not exist)
我有一个包含多个子组件的组件。在下面的代码中,我获取组件,然后使用“cls=ngp”获取其所有子组件。然后我遍历它们并尝试将它们从父面板中删除。
var ptp = Ext.ComponentQuery.query('partytoolpanel')[0]; //there is only ever one instance!!
var comps = Ext.ComponentQuery.query('partytoolpanel [cls=ngp]') //6 objects are returned here!!
comps.forEach(function (c) {
ptp.remove(c);
})
comps 没有被删除,而是我收到这条消息:
Attempted to remove a component that does not exist.
Ext.container.Container: remove takes an argument of the component to
remove. cmp.remove() is incorrect usage.
我试图在 fiddle 中重现这个问题,当然,它完美地工作:(
https://fiddle.sencha.com/#fiddle/1irm
为什么我的案例不起作用?
组件查询 partytoolpanel [cls=ngp]
将匹配具有 class 的所有组件,这些组件位于具有 xtype: 'partytool'
的组件下方的层次结构中,而不仅仅是直接子级。
但是 container.remove
函数只能删除 container
的直接子组件。
您应该从循环内的直接父级中删除组件:
Ext.each(comps, function (c) {
c.up().remove(c);
})
(我建议您使用 Ext.each(array, fn)
而不是 array.forEach(fn)
,这样 Sencha 可以解决任何浏览器问题。)
我有一个包含多个子组件的组件。在下面的代码中,我获取组件,然后使用“cls=ngp”获取其所有子组件。然后我遍历它们并尝试将它们从父面板中删除。
var ptp = Ext.ComponentQuery.query('partytoolpanel')[0]; //there is only ever one instance!!
var comps = Ext.ComponentQuery.query('partytoolpanel [cls=ngp]') //6 objects are returned here!!
comps.forEach(function (c) {
ptp.remove(c);
})
comps 没有被删除,而是我收到这条消息:
Attempted to remove a component that does not exist. Ext.container.Container: remove takes an argument of the component to remove. cmp.remove() is incorrect usage.
我试图在 fiddle 中重现这个问题,当然,它完美地工作:( https://fiddle.sencha.com/#fiddle/1irm
为什么我的案例不起作用?
组件查询 partytoolpanel [cls=ngp]
将匹配具有 class 的所有组件,这些组件位于具有 xtype: 'partytool'
的组件下方的层次结构中,而不仅仅是直接子级。
但是 container.remove
函数只能删除 container
的直接子组件。
您应该从循环内的直接父级中删除组件:
Ext.each(comps, function (c) {
c.up().remove(c);
})
(我建议您使用 Ext.each(array, fn)
而不是 array.forEach(fn)
,这样 Sencha 可以解决任何浏览器问题。)