1

我在这里遇到了一个相当奇怪的错误/问题,我似乎无法弄清楚。

在我的网格的双击事件中,我正在向我的 Api 控制器发送一个带有 Id 的请求,以获取一个“合同”记录以加载到 ExtJs 端的表单中。.NET 调试发回包含所有字段的正确“合同”记录。

网络流量还显示记录已检索到所有字段,如下所示。 网络流量记录在案

但是,在我的加载成功回调中记录记录时,我只有 ID 字段。控制台日志记录

这意味着当将我的记录加载到我的表单中时,没有显示任何字段。

模型如下图,

Ext.define('Heating.model.contract.Contract', {
    extend: 'Ext.data.Model',

    fields: [
        { name: 'id', type: 'auto' },
        { name: 'organisationId', type: 'auto' },
        { name: 'organisation', type: 'auto' },
        { name: 'systemTypeId', type: 'auto' },
        { name: 'systemType', type: 'auto' },
        { name: 'description', type: 'auto' },
        { name: 'deleted', type: 'auto' },
        { name: 'startDate', type: 'date' },
        { name: 'endDate', type: 'date' },
        { name: 'lastModified', type: 'date', dateFormat: 'c' }

    ],

    validations: [
      { type: 'presence', field: 'description'},
      { type: 'length',   field: 'description',  max: 255},
      { type: 'presence', field: 'organisationId'}
    ],

    proxy: {
        type: 'rest',
        url: Heating.util.Config.BaseUrl + 'api/contract',
        noCache: true,
        filterParam: 'filter',
        reader: {
            type: 'json',
            root: 'data',
            totalProperty: 'total',
            messageProperty: 'message'
        },
        writer: {
            type: 'json'
        }
    }
});

和存储,

Ext.define('Heating.store.contract.Contracts', {

extend: 'Ext.data.Store',
model: 'Heating.model.contract.Contract',
storeId: 'contracts',
autoLoad: false,
remoteFilter: true,
listeners: {
    load: function(store, records) {
        console.log('Contract store loaded');
        console.log(store.getCount());
    }
}
});

有任何想法吗?提前致谢!

4

1 回答 1

1

这张图片中的data属性在我看来是错误的。

网络流量记录在案

似乎您的记录位于另一个数组内部的数组中。像这样(不正确):

{
success: true,
total: 1,
message: 'blah blah blah',
data: 
    [
        [
           {
           id: "record-1",
           //etc
           }, {
           id: "record-2",
           //etc
           }
        ]
    ]
}

数据根应该是从服务器端返回的单个记录对象数组,如下所示:(正确

{
success: true,
total: 1,
message: 'blah blah blah',
data: 
    [
        {
        id: "record-1",
        //etc
        }, {
        id: "record-2",
        //etc
        }
    ]
}
于 2014-03-20T17:54:43.067 回答