Domanda

Sono nuovo in EXTJS 4 e sto cercando di implementare una semplice applicazione in stile MVC. La documentazione è davvero buona e questo è uno degli argomenti trattati nella guida al pacchetto di moduli, ma non sembra funzionare nel mio caso.

L'app in pratica può creare, modificare ed eliminare articoli. La creazione e l'editing sono nelle finestre pop-up. La finestra pop-up contiene un modulo con un campo di testo e un editor HTML. Fare clic sul link in basso, questo è l'errore nella console di Google Chrome quando faccio clic sul pulsante di invio nella "Finestra"

http://www.freeimagehosting.net/mjig7

Ecco il codice che ho scritto modello:

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

Visualizzazione:

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

e infine il codice nel mio controller che rende visibile la finestra

Controller:

.....

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

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

Per favore indicami nella giusta direzione nel caso in cui sto facendo qualcosa di sbagliato. Grazie in anticipo.

È stato utile?

Soluzione

Controlla i documenti getRecord ():

Restituisce l'ultima istanza Ext.Data.Model che è stata caricata tramite loadRecord

Quindi è chiaro che non hai caricato alcun record, quindi otRecord () restituisce indefinito. E stai ottenendo ulteriori errori.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top