2014-01-29 68 views
0

當我點擊Edit按鈕時,出現錯誤Uncaught TypeError: Object #<Object> has no method 'apply'。這是我的面板:Uncaught TypeError:Object#<Object> has no method'apply'error

Ext.define(
    "ux.panel.MyPanel", { 
    extend : "Ext.form.Panel", 
    xtype : "MyPanel", 
    title : "Bla bla title" 

    initComponent : function() { 
     ux.panel.MyPanel.superclass.initComponent.call(this); 
    }, 
    init : function (initParameters) { 
     this.initParameters = initParameters; 

     this.removeAll(true); 

     if (this.initParameters == null) 
      return; 
    }, 
    editSomething : function() { 
     alert("editTV"); 
    }, 
    tbar : [{ 
      text : "Edit" 
      iconCls : "silk-edit-16", 
      id : "editbutton", 
      disabled : false, 
      listeners : { 
       click : { 
        scope : this, 
        fn : this.editSomething 
       } 
      } 
     }, { 
      text : "Remove", 
      iconCls : "silk-delete-16", 
      id : "removeButton", 
      disabled : false, 
      listeners : { 
       click : { 
        scope : this, 
        fn : function() { 
         alert("RemoveTV"); 
        } 
       } 
      } 
     } 
    ] 
}); 

此面板包含在由許多其他面板組成的頁面中。我懷疑這在這個編輯器裏有什麼不是指向我的小組。我對如何處理這個問題沒有任何線索。

有人對此有何想法?

回答

2

那是因爲this不是你所期望的。

添加tbarinitComponent功能,如:

initComponent: function() { 
    Ext.apply(this, { 
     tbar: [{ 
      text: "Edit", 
      iconCls: "silk-edit-16", 
      id: "editbutton", 
      disabled: false, 
      listeners: { 
       click: { 
        scope: this, 
        fn: this.editSomething 
       } 
      } 
     }, { 
      text: "Remove", 
      iconCls: "silk-delete-16", 
      id: "removeButton", 
      disabled: false, 
      listeners: { 
       click: { 
        scope: this, 
        fn: function() { 
         alert("RemoveTV"); 
        } 
       } 
      } 
     }] 
    }); 

    this.callParent(arguments); 
} 

http://jsfiddle.net/gkcU7/

+0

謝謝你這麼多CD .. – Sofiane

相關問題