【问题标题】:json not matching modeljson不匹配模型
【发布时间】:2012-08-10 12:14:51
【问题描述】:

在 EXTJS 中,我将使用模型并存储我的网格。现在是有时json与模型不匹配的问题。然后在我的模型中将有更少的信息。发生这种情况时,EXTJS 不会在网格中显示任何数据。所以我找了一个修复程序,发现了这个:

Ext.define('App.Reader', {
extend: 'Ext.data.reader.Json',

extractData: function(root) {
    var me = this,
        values  = [],
        records = [],
        Model   = me.model,
        i       = 0,
        length  = root.length,
        idProp  = me.getIdProperty(),
        node, id, record;

    if (!root.length && Ext.isObject(root)) {
        root = [root];
        length = 1;
    }

    for (; i < length; i++) {
        node   = root[i];
        values = me.extractValues(node);
        id     = me.getId(node);

        record = new Model(values, id, node);
        records.push(record);

        if (me.implicitIncludes) {
            me.readAssociated(record, node);
        }

    }

    return records;
},

extractValues: function(data) {
    var fields = this.getFields(),
        i      = 0,
        length = fields.length,
        output = {},
        field, value;

    for (; i < length; i++) {
        field = fields[i];
        value = this.extractorFunctions[i](data);

        if(value === undefined)
        {
            Ext.iterate(fields, function(key, val) {
                if (data[key] === undefined & i==val) {
                    console.log( "Model field <" + key.name + "> does not exist in data/node.");
                    value = "INVALID OR MISSING FIELD NAME";
                    var p = 0;
                    for(var prop in data) {
                        if(p==i){
                            if(data.hasOwnProperty(prop))console.log("Instead of <" + key.name + "> we have <" + prop + "> with value <" + data[prop]+ ">");
                        }
                        p++;
                    }
                }
            }, this);
        }

        output[field.name] = value;
    }

    return output;
}

});

var myReader = new App.Reader({
type:'json'
});

我在网上找到了这个。但是当我将它与 EXTJS 4.1.1 一起使用时,ext-all 出现错误:TypeError: j is undefined.

我应该在哪里寻找解决方法?

【问题讨论】:

    标签: json extjs model grid store


    【解决方案1】:

    没有必要做一些复杂的事情来解决这个微不足道的问题。阅读Ext.data.ModelExt.data.Field,正确配置您的模型,一切就绪。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-22
      • 1970-01-01
      • 2014-02-05
      • 2021-02-10
      相关资源
      最近更新 更多