0

我是 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');
    },

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

4

1 回答 1

0

检查文档getRecord()

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

所以很明显你没有加载任何记录,所以你 getRecord() 返回未定义。而且您的错误会进一步加深。

于 2012-02-19T07:52:33.413 回答