2011-11-13 35 views
0

我目前在Ext JS 3.1.0中教EditorGridPanel。我設法創建了一個顯示城市列表的網格。但是,當我嘗試向數據庫中添加新記錄時遇到問題。當我點擊按鈕「添加城市」沒有任何反應和Firebug的顯示錯誤:我無法在EditorGridPanel中添加新記錄

Uncaught ReferenceError: newCity is not defined 
Ext.grid.EditorGridPanel.tbar.handlereg02.html: 96 
Ext.Button.Ext.extend.onClickext-all-debug.js: 27083 
h 

這是我的代碼:

Ext.onReady(function(){ 

//===== Data Store ================================================== (2) 
var store = new Ext.data.Store({ 
       url: 'city_for_eg01.php', 
       reader: new Ext.data.JsonReader({ 
       root:'rows', 
       id:'zip' 
      }, [ 
       'zip', 
       'city' 
      ]), 
      api: { 
        create : 'city_for_eg01.php?action=create', 
        read : 'city_for_eg01.php?action=read', 
        update: 'city_for_eg01.php?action=update', 
        destroy: 'city_for_eg01.php?action=destroy' 
       }, 
      writer: new Ext.data.JsonWriter({ 
       writeAllFields: true 
       }), 
      autoSave: false, 
     }); 
store.load(); 
//=================================================================== end (2) 

var editor = new Ext.form.TextField(); 

var grid = new Ext.grid.EditorGridPanel({ 
     renderTo: document.body, 
     frame:true, 
     title: 'City', 
     height:200, 
     width:520, 
     clickstoEdit: 1, 
     store: store, 
     columns: [ 
        {header: "ZIP", dataIndex: 'zip', editor: editor}, 
        {header: "CITY", dataIndex: 'city', editor: editor}, 
        ], 
     listeners: { 
        afteredit: function(e){e.record.commit();} 
     }, 
     tbar: [{ 
      text: 'Add City', 
      icon: 'images/table_add.png', 
      cls: 'x-btn-text-icon', 
      handler: function() { 
         Ext.Ajax.request({ 
           url: 'city-update.php', 
           params: { 
              action: 'create', 
              zip: 'zip' 
             }, 
           success: function(resp,opt) { 
              grid.getStore().insert(0, 
              new newCity{ 
                zip: 'New Zip', 
                city: 'New City'  
                }) 
             ); 
              grid.startEditing(0,0); 
          }, 
           failure: function(resp,opt) { 
                Ext.Msg.alert('Error','Unable to add city'); 
                } 
        }); 
       } 
     }]    
    }); 
}); 

回答

1

這是因爲沒有定義newCity功能。

您應該能夠使其與工作:

new store.recordType(/* values */) 

recordType適用於所有存儲新Record構造。