简体   繁体   English

将Ext.data.JsonReader从ExtJs 3转换为ExtJs 4

[英]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. 我正在尝试将此阅读器从Ext 3转换为Ext4。JavaScript引发异常。 Did I convert this correctly? 我正确转换了吗?

JavaScript exception: JavaScript例外:

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. JsonReader的构造函数仅接受一个参数。 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... 这就是当商店缺少字段声明时遇到的错误类型...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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