Sofiane
Sofiane

Reputation: 950

creating extjs store data record is failing

I have the error Uncaught TypeError: Cannot read property 'items' of undefined
The following line where I create the NewEditInfo type. The alert shows there are values in the arrays so I have no clue..

getNewEditInfo : function () {
        var values = {};
        var form = this.getForm();
        var formValues = form.getValues();
        for (var fieldName in formValues)
            values[fieldName] = (formValues[fieldName] != "") ? formValues[fieldName] : null;
        alert(JSON.stringify(values));
        alert(JSON.stringify(formValues));
        NewEditInfo = Ext.data.Record.create([{
                        name : "id",
                        type : "string"
                    }, {
                        name : "hardwareId",
                        type : "string"
                    }, {
                        name : "location",
                        type : "string"
                    }, {
                        name : "active",
                        type : "string"
                    }
                ]);

        var newEditInfoInstance = new NewEditInfo({
                id : values['idField'],
                hardwareId : values['hardwareIdField'],
                location : values['location '],
                active : values['active']
            });
        return newEditInfoInstance;
    }

Can anyone help please?

Upvotes: 1

Views: 1415

Answers (1)

Akatum
Akatum

Reputation: 4016

Ext.data.Record.create() does not return model class but new model instance.

Firstly you should define your own model:

Ext.define('editInfoModel', {
    extend: 'Ext.data.Model',
    fields: [
        {
            name : "id",
            type : "string"
        }, {
            name : "hardwareId",
            type : "string"
        }, {
            name : "location",
            type : "string"
        }, {
            name : "active",
            type : "string"
        }
    ]
});

Then in your getNewEditInfo method you can create new instance of editInfoModel and set record data by Ext.create() method:

var newEditInfoInstance = Ext.create('editInfoModel', {
    id : values['idField'],
    hardwareId : values['hardwareIdField'],
    location : values['location '],
    active : values['active']
});

Upvotes: 1

Related Questions