EXT.Js api响应数据未绑定到存储



在商店上调用加载方法时遇到问题。我的api提供了正确的数据,我可以在chrome网络选项卡中看到,但在存储对象中,数据丢失了参见下方的示例代码

店铺创建

_createStore: function()
{
return new Ext.data.Store({
proxy:
{
url: //api call which returns single object of below data feild  ,
appName: 'myApp',
appendIdForCreate: false,
reader: {
type: 'json'
},
fields: [
{ name: 'id', type: 'int' },
{ name: 'employeeId', type: 'int' },
{ name: 'start', type: 'date' },
{ name: 'end', type: 'date' },
{ name: 'details', type: 'auto' },
{ name: 'audits', type: 'auto' },
.
.
.
.
....... Some more properties
]
});
},

API响应示例

{
"id": 1234567,
"employeeId": 123456,
"start": "2022-01-13T00:00:00",
"end": "2022-01-13T00:00:00",
"details": [{
"detailId": "123456789",
"date": "2022-01-13T00:00:00",
"startOfWeek": "0001-01-01T00:00:00"
}
],

"audits": [{
"timestamp": "2022-01-10T04:24:43",
"comment": "test comment",
"authorLastName": "Naikele",
"authorFirstName": "Sagar"
}]
}

当我调用
var myStore=_createStore((时;myStore.load((;

我正在从API正确地获取数据,我可以在chrome网络选项卡中看到但我在myStore中找不到任何数据不知道我做错了什么!存储数据在此处输入图像描述

API响应在此处输入图像描述

Proxy没有field属性。定义您的模型,如:

Ext.define('MyModel', {
extend: 'Ext.data.Model',
fields: [{
name: 'id',
type: 'int'
},{
name: 'employeeId',
type: 'int'
} // additional fields
],
});

然后在创建商店时使用此模型。此外,设置代理类型也是一个好主意:

return new Ext.data.Store({
model: 'MyModel',
proxy: {
type: 'ajax' // or 'rest' etc
url: 'url',
}
...
});

最新更新