【问题标题】:ExtJS 4 MVC Application: Form undefined errorExtJS 4 MVC 应用程序:表单未定义错误
【发布时间】:2012-03-09 23:25:51
【问题描述】:

我是 ExtJS 4 的新手,正在尝试以 MVC 风格实现一个简单的应用程序。文档非常好,这是表单包指南中涵盖的主题之一,但在我的情况下似乎不起作用。

该应用程序基本上可以创建,编辑和删除文章。创建和编辑是在弹出窗口中。 弹出窗口包含一个带有文本字段和 html 编辑器的表单。 请点击下面的链接,这是我点击“窗口”中的提交按钮时谷歌浏览器控制台中的错误

http://www.freeimagehosting.net/mjig7

这是我写的代码 型号:

Ext.define('AM.model.Article', {
    extend: 'Ext.data.Model',
    fields: ['name', 'data'],
    proxy: {
        type: 'rest',
        url: 'users/data',
        reader: {
            type: 'json',
            root: 'myJaxBean',
            successProperty: 'success'
        },
        writer: {
            type: 'json'
        }
    }
});

查看:

Ext.define('AM.view.New', {
    extend: 'Ext.window.Window',
    alias : 'widget.new',
    title : 'New Article',
    autoShow: true,
    fieldDefaults: {
        labelAlign: 'top',
        msgTarget: 'side'
    },
    layout: 'fit',
    bodyStyle:'padding:5px 5px 0',
    width: '70%',
    height: '40%',
    initComponent: function() {
        this.items = [
            {
                xtype: 'form',
                anchor: '99%',
                items: [
                    {
                        xtype: 'textfield',
                        name : 'name',
                        fieldLabel: 'Article Name',
                        anchor: '99%'
                    },
                    {
                        xtype: 'htmleditor',
                        name : 'data',
                        fieldLabel: 'Article',
                        anchor: '99% -25'
                    }
                ],
                buttons: [
                {
                    text: 'Submit',
                    handler: function() {
                        var form = this.up('form').getForm(), // get the basic form
                            record = form.getRecord(); // get the underlying model instance
                        if (form.isValid()) { // make sure the form contains valid data before submitting
                            form.updateRecord(record); // update the record with the form data
                            record.save({ // save the record to the server
                                success: function(user) {
                                    Ext.Msg.alert('Success', 'User saved successfully.')
                                },
                                failure: function(user) {
                                    Ext.Msg.alert('Failure', 'Failed to save user.')
                                }
                            });
                        } else { // display error alert if the data is invalid
                            Ext.Msg.alert('Invalid Data', 'Please correct form errors.')
                        }
                    }
                },
                {
                    text: 'Cancel',
                    scope: this,
                    handler: this.close
                }
            ]
            }
        ],


        this.callParent(arguments);
    }
});

最后是我的控制器中使窗口可见的代码

控制器:

.....

'viewport > panel > panel > tbar button[action=newarticle]' :{
                click: this.newArticle
            },
....

   newArticle: function(button){
        var view = Ext.widget('new');
    },

如果我做错了什么,请指出正确的方向。 提前致谢。

【问题讨论】:

    标签: forms model-view-controller extjs store article


    【解决方案1】:

    查看文档getRecord()

    返回通过加载的最后一个 Ext.data.Model 实例 加载记录

    所以很明显你没有加载任何记录,所以你 getRecord() 返回未定义。而且你的错误越来越严重。

    【讨论】:

    • 是的,我想通了。现在我使用 Ext.create.Record 创建一个新记录,并将其加载到表单中,然后再为其分配值。感谢您的努力。
    猜你喜欢
    • 1970-01-01
    • 2017-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多