ExtJS模型原始数据在加载时不与实际记录同步

时间:2014-04-09 11:38:12

标签: extjs model store sync

我有一个模特

Ext.define('MyCompany.model.Customer', {
    extend: 'Ext.data.Model',

    fields: [
        'id', 'name', 'taxID', 'tradeID', 'vatID', 'email'
    ]
}

和商店

Ext.define('MyCompany.store.Customers', {
    extend: 'MyCompany.lib.base.Store',

    model: 'MyCompany.model.Customer',

    api: {
        read: $["crmModule.CustomerController"].list,
        create: $["crmModule.CustomerController"].save
    }
});

问题是,在调用store.load()时(例如从控制台调用),字段vatID未同步。我可以在store.data.items[0].raw中看到该字段,但在store.data.items[0].data中该字段为空。我该如何调试此问题? ExtJS在哪里进行从原始数据到实际记录的转换?

1 个答案:

答案 0 :(得分:0)

查找为extractData定义的名为Ext.data.reader.Reader的方法。有以下几行:

// If the server did not include an id in the response data, the Model constructor will mark the record as phantom.
// We  need to set phantom to false here because records created from a server response using a reader by definition are not phantom records.
record.phantom = false;

// Use generated function to extract all fields at once
me.convertRecordData(convertedValues, node, record);

records.push(record);

当您进入方法convertRecordData时,您将看到生成的临时代码以进行实际转换,如下所示:

return function(dest, source, record) {
    value = source["id"];
    if (value !== undefined) {
        dest["id"] = value;
    }
    value = source["name"];
    if (value === undefined) {
        if (me.applyDefaults) {
    ...