EXT.Js api 响应数据未绑定到存储
EXT.Js api response data is not binding to store
我在商店上调用加载方法时遇到问题。
我的 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 中找不到任何数据
不知道我在做什么错!
存储数据
enter image description here
API 回复
enter image description here
代理没有 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',
}
...
});
我在商店上调用加载方法时遇到问题。 我的 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 中找不到任何数据 不知道我在做什么错! 存储数据 enter image description here
API 回复 enter image description here
代理没有 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',
}
...
});