2012-04-22 103 views
1

我在EXT庫初學者,我試圖延長網格面板,並從我的新類記錄一個引用其商店:this.store未定義

Ext.define('App.ui.CategoryGridPanel', { 
extend : 'Ext.grid.Panel', 
initComponent : function() { 
    var storeToUse = this.store; 

    if (storeToUse == null) { 
     storeToUse = Ext.data.StoreManager.lookup(StoreIDs.CategoryStore); 
    } 

    this.categoryRowEditing = Ext.create('Ext.grid.plugin.RowEditing', { 
     clicksToEdit : 2, 
     store : storeToUse, 
     listeners : { 
      edit : function(editor, e) { 
       this.store.sync(); 
      } 
     } 
    }); 

    Ext.apply(this, { 
     store : storeToUse, 
     height : 400, 
     width : 300, 
     plugins : [ this.categoryRowEditing ], 
     columns : [ { 
      header : 'Description', 
      dataIndex : 'description', 
      flex : 1, 
      sortable : true, 
      editor : 'textfield' 
     } ], 
     tbar : [ { 
      xtype : 'button', 
      text : 'New', 
      handler : this.insertNewCategory 
     } ] 
    }); 

    this.callParent(arguments); 
}, 
/** 
* Add new Category to grid. 
*/ 
insertNewCategory : function() { 
    var category = Ext.create(ModelNames.Category, { 
     description : '' 
    }); 

    this.store.insert(0, category); 
    this.categoryRowEditing.startEdit(0, 0); 
} 

});

方法inserNewCategory總是拋出放一些提醒我發現this.store返回null後不能打電話的不確定 插入。 我檢查了分機示例代碼,但我沒有做任何不同的事情。

請幫助:(

回答

1
  1. 檢查你看到在你的insertNewCategory方法this你會驚訝我的賭注 - 。這將是你按下按鈕,因爲你沒做什麼關於此功能的範圍

  2. 閱讀Sencha指南和步驟從您的代碼示例中可以清楚地看到您正在以完全錯誤的方式使用它 - 您不需要執行所有這些手動工作來分配和重新設置 - 指定商店 - 這全部由ExtJs自動處理。

+1

非常感謝兩件事,回答我的問題,並給我提示在哪裏尋找。 – 2012-04-22 11:53:18

+0

如果答案適用於您 - 請將其標記爲「已回答」。 – sha 2012-04-22 11:54:33

0

這似乎是你的類對象的創建失敗:

var category = Ext.create(ModelNames.Category, { 
    description : '' 
}); 

我會把突破這條線之後,以確保您的「類」對象已正確創建。

關於使用'這個',我建議你看看它的直接使用的危險。許多場景可能會導致它不是您所期望的。請參閱here瞭解關於javascript陷阱的更多信息。