简体   繁体   中英

Convert Ext.data.JsonReader from ExtJs 3 to ExtJs 4

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: {

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM