0

我正在尝试将此阅读器从 Ext 3 转换为 Ext 4。JavaScript 正在引发异常。我正确转换了吗?

JavaScript 异常:

Uncaught TypeError: Cannot read property 'prototype' of undefined 

代码(转换后的行注释):

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

编辑:

修复了这个:

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

并添加模型:

    var store = Ext.create('Ext.data.DirectStore', {
        model: 'User',
        api: {
4

1 回答 1

1

JsonReader 的构造函数只接受一个参数。所以你的代码并没有真正定义字段列表。然而,字段列表是强制性的,无论是在商店中(如果商店不使用模型),还是在模型中。这就是商店缺少字段声明时遇到的错误类型...

于 2013-07-29T06:07:11.473 回答