javascript - 无法从 tabpanel 中的表单获取值

标签 javascript extjs extjs6 extjs6-modern

我不知道如何从表单字段中获取值。表格是来自选项卡面板内的项目之一。导致控制台抛出这个:

"Uncaught TypeError: charform.getValues is not a function"

当我使用它从表单中获取值时,我没有遇到问题:

var dataupNew = this.up().items.items[0];
var dataSetNew = dataupNew.getValues();  

这是我的代码:

Ext.define('Foresto.view.forms.Cutarea', {
    extend: 'Ext.panel.Panel',
    title: 'Les',
    margin: 5,
    height: 600,
    scrollable: true,
    xtype: 'foresto-cutarea',
    items: [{
        xtype: 'tabpanel',
        cls: 'grbuttons',
        layout: 'card',
        items: [{
            xtype: 'panel',
            cls: 'grbuttons',
            layout: 'vbox',
            title: 'Characteristic',
            items: [{
                xtype: 'selectfield',
                label: 'number'
            }, {
                xtype: 'textfield',
                label: 'tract'
            }, {
                xtype: 'selectfield',
                label: 'task',
                name: 'targetUsing'
            }, {
                xtype: 'button',
                text: 'save',
                cls: 'grbuttons',
                margin: 10,
                ui: 'confirm',
                handler: function () {
                    var charform = this.up('panel');
                    var charSet = charform.getValues();

                    Ext.Ajax.request({
                        url: '/api/characteristic/',
                        method: 'POST',
                        params: charSet
                    });
                }
            }]
        }]
    }]
});

我希望该处理程序执行 POST 查询。但现在我有这个:

Uncaught TypeError: charform.getValues is not a function

最佳答案

首先你需要在 tabpanel 范围内使用 this.up('panel'),然后你需要 this.up('form') 来获取实际的表单,最后你可以获得你的值

检查这个工作示例 Extjs Fiddle

Ext.application({
    name: 'Fiddle',

    launch: function () {
        Ext.create('Ext.form.Panel', {
            title: 'Les',
            margin: 5,
            height: 600,
            renderTo:Ext.getBody(),
            scrollable: true,
            items: [{
                xtype: 'tabpanel',
                layout: 'card',
                items: [{
                    xtype: 'panel',
                    layout: 'vbox',
                    title: 'Characteristic',
                    items: [ {
                        xtype: 'textfield',
                        label: 'tract'
                    }, {
                        xtype: 'button',
                        text: 'save',
                        margin: 10,
                        handler: function () {
                            var charpanel = this.up('panel');
                            var charform = charpanel.up('form');
                            var charSet = charform.getValues();

                            Ext.Ajax.request({
                                url: '/api/characteristic/',
                                method: 'POST',
                                params: charSet
                            });
                        }
                    }]
                }]
            }]
        });
    }
});

关于javascript - 无法从 tabpanel 中的表单获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54456597/

相关文章:

javascript - AngularJS orderBy 问题

javascript - 使用 jsduck 记录事件处理程序的最佳方法是什么?

javascript - 如何像在 JqGrid 中一样创建 ExtJS Grid 工具栏搜索

javascript - 所有树列中的图标和箭头

php - 对于每个循环和 fancybox

javascript - 将表单传递给指令 : undefined

javascript - Foundation 6 Canvas 外未关闭

javascript - 边框布局中的折叠面板 : Permanent expand on title-click

java - 使用 Java、Spring、Jsp、Extjs 获取 Wildfly 8.2.0 Final - Undertow "UT010019: Response already commited"错误

extjs - 在网格标题 extjs 6 中过滤