Question

I'm trying to convert this reader from Ext 3 to Ext 4. JavaScript is throwing an exception. Did I convert this correctly?

JavaScript exception:

Uncaught TypeError: Cannot read property 'prototype' of undefined 

Code (converted lines commented):

Ext.onReady(function () {

    Ext.Direct.addProvider(Ext.app.REMOTING_API);

    //var reader = new Ext.data.JsonReader({  // convert from ext 3 to ext 4
    var reader = Ext.create('Ext.data.JsonReader', {
        totalProperty: 'results',
        successProperty: 'success',
        idProperty: 'id',
        root: 'data'
    }, [{
        name: 'id'
    }, {
        name: 'email',
        allowBlank: false
    }, {
        name: 'first',
        allowBlank: false
    }, {
        name: 'last',
        allowBlank: false
    }]
    );

    //var writer = new Ext.data.JsonWriter({  // convert from ext 3 to ext 4
    var writer = Ext.create('Ext.data.JsonWriter', {
        returnJson: false,
        writeAllFields: true
    });

    //var store = new Ext.data.DirectStore({  // convert from ext 3 to ext 4
    var store = Ext.create('Ext.data.DirectStore', {
        api: {
            read: CRUDSampleMethods2.read,
            create: CRUDSampleMethods2.create,
            update: CRUDSampleMethods2.update,
            destroy: CRUDSampleMethods2.destroy
        },
        reader: reader,
        baseParams: {
            dummy: 'blubb'
        },
        writer: writer,
        paramsAsHash: true,
        batchSave: false,
        batch: false,
        prettyUrls: false,
        remoteSort: true,
        listeners: {
            load: function (result) { },
            loadexception: function () {

            },
            scope: this
        }
    });

    // ... code continues

EDIT:

Fixed this:

var reader = Ext.create('Ext.data.JsonReader', {
    totalProperty: 'results',
    successProperty: 'success',
    idProperty: 'id',
    root: 'data'
});

And added model:

    var store = Ext.create('Ext.data.DirectStore', {
        model: 'User',
        api: {
Was it helpful?

Solution

JsonReader's constructor accept only one param. So your code doesn't really define the field list. Yet the field list is mandatory, either in the store (if the store doesn't use a model), or the model. And that's the type of error you get when a store is missing fields declaration...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top