---
title: "给Ext.Toolbar加上remove方法以移除子组件"
author: "chanball"
date: "2010-02-08T10:02:11Z"
tags: []
categories: ["Web前端"]
slug: "ext-toolbar-remove"
draft: false
lastmod: "2010-02-08T10:02:11Z"
id: 591265
url: "https://javaExtjs.iteye.com/blog/591265"
---

在用Ext.Toolbar的时候,发现竟然没有remove方法,这样就删除不了item啦,加上下面两个方法.

```js


remove : function(comp, autoDestroy){
        var c = this.getComponent(comp);
        if(c && this.fireEvent('beforeremove', this, c) !== false){
            this.items.remove(c);
            delete c.ownerCt;
            if(autoDestroy === true || (autoDestroy !== false && this.autoDestroy)){
                c.destroy();
            }
            this.fireEvent('remove', this, c);
        }
        return c;
    },
    getComponent : function(comp){
        if(typeof comp == 'object'){
            return comp;
        }
        return this.items.get(comp);
    }

```