【问题标题】:Adding CSV upload browse button to Ext.Action将 CSV 上传浏览按钮添加到 Ext.Action
【发布时间】:2012-09-24 19:32:42
【问题描述】:

我正在尝试在 GeoExt Map App 上创建 CSV 文件上传。 我需要将上传功能放在 Ext.Action 中,以便我可以将其添加到 GeoExt 面板的工具栏中。我正在尝试实现这个example。这是我的代码,

    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));

Firebug 一直给我这个错误,

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

我是否在 Ext.Action 中错误地声明了函数?

【问题讨论】:

  • 你解决了吗?我遇到了同样的问题...

标签: file-upload extjs csv openlayers extjs3


【解决方案1】:

您不能直接将action 推入toolbar,因为Ext.Action 不是Ext.Component 的类型。 Ext.Action 基本上是一种创建可以多次重用的抽象层的方法。在这里您需要执行以下操作:

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

来自documentation

Actions 让您可以共享处理程序、配置选项和 UI 更新 跨任何支持 Action 接口的组件(主要是 Ext.toolbar.Toolbar、Ext.button.Button 和 Ext.menu.Menu 组件)

【讨论】:

  • 那么我该如何为那个按钮添加功能呢?
  • 就像我在答案toolbarItems.push(new Ext.button.Button(action));中所说的
  • 我更新了代码,但错误仍然存​​在。它仍然给我同样的错误。您可以在 firebug 中看到错误,128.196.142.12/geo/test/test_new.html
  • 你不能使用new Ext.create()。那就是问题所在。它应该只是Ext.create
  • 抱歉,还是不行。我更新了代码。它继续给我同样的错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-06
  • 2010-11-30
  • 1970-01-01
  • 1970-01-01
  • 2012-06-29
  • 2015-11-04
  • 1970-01-01
相关资源
最近更新 更多