2012-09-24 90 views
1

我正嘗試在GeoExt地圖應用上創建一個CSV文件上傳。 我需要將上傳功能放在Ext.Action中,以便我可以將其添加到GeoExt面板的工具欄中。我正試圖執行這個example。這裏是我的代碼,添加CSV上傳瀏覽按鈕到Ext.Action

action = new Ext.Action({ 
    text: "Upload Excel", 
    control: Ext.create('Ext.form.Panel', { 
     title: 'Upload a CSV File', 
     width: 400, 
     bodyPadding: 10, 
     frame: true, 
     renderTo: Ext.getBody(), 
     items: [{ 
      xtype: 'filefield', 
      name: 'csv', 
      fieldLabel: 'CSV Upload', 
      labelWidth: 50, 
      msgTarget: 'side', 
      allowBlank: false, 
      buttonText: 'Select CSV File' 
     }], 

     buttons: [{ 
      text: 'Upload', 
      handler: function() { 
       var form = this.up('form') 
        .getForm(); 
       if (form.isValid()) { 
        form.submit({ 
         url: 'file-upload.py', 
         waitMsg: 'Uploading the CSV File...', 
         success: function (fp, o) { 
          Ext.Msg.alert('Success', 'Your csv file "' + o.result.file + '" has been uploaded.'); 
         } 
        }); 
       } 
      } 
     }] 
    }), 
    map: map, 
    // button options 
    tooltip: "Upload CSV File", 
    // check item options 
    group: "newTool" 
}); 
actions["upCSV"] = action; 
toolbarItems.push(new Ext.button.Button(action)); 

螢火蟲不斷給我這個錯誤,

TypeError: b[d.xtype || e] is not a constructor

難道我不當聲明Ext.Action內的功能?

+0

你設法解決這個問題嗎?我遇到了同樣的問題... – avn

回答

1

由於Ext.Action不是Ext.Component類型,所以不能直接將action轉換爲toolbar。一個Ext.Action基本上是創建一個可以多次重用的抽象層的方法。在這裏,你需要做到以下幾點:

toolbarItems.push(new Ext.button.Button(action)); 

documentation

操作讓你分享處理器,配置選項和UI更新 跨越支持Action接口(主要 分機的所有組件。 toolbar.Toolbar,Ext.button.Button和Ext.menu.Menu組件)

+0

然後如何向該按鈕添加功能? – Sam007

+0

就像我在回答'toolbarItems.push(new Ext.button.Button(action));' –

+0

我更新了代碼,但錯誤仍然存​​在。它仍然給我同樣的錯誤。你可以在螢火蟲中看到錯誤,http://128.196.142.12/geo/test/test_new.html。 – Sam007