Pregunta

Soy nuevo en ExtJS 4 y estoy tratando de implementar una aplicación simple en estilo MVC. La documentación es realmente buena y este es uno de los temas cubiertos en la guía del paquete de formulario, pero no parece funcionar en mi caso.

La aplicación básicamente puede crear, editar y eliminar artículos. La creación y la edición están en ventanas emergentes. La ventana emergente contiene un formulario con un campo de texto y un editor HTML. Haga clic en el enlace a continuación, este es el error en la consola de Google Chrome cuando hago clic en el botón Enviar en la 'ventana'

http://www.freeimagehosting.net/mjig7

Aquí está el código que he escrito modelo:

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

Vista:

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

y finalmente el código en mi controlador que hace que la ventana sea visible

Controlador:

.....

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

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

Por favor, señale en la dirección correcta en caso de que esté haciendo algo mal. Gracias por adelantado.

¿Fue útil?

Solución

Revise los documentos getRecord ():

Devuelve la última instancia ext.data.model que se cargó a través de LoadRecord

Por lo tanto, está claro que no ha cargado ningún registro, por lo que getRecord () devuelve indefinido. Y está recibiendo su error más.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top