Sencha Ext JS数据未显示在网格中



我是Sencha Extjs的新手,我试图从我在asp.net中创建的API中提取数据。

在开发人员工具中,我可以获得数据,但它没有显示在网格中。有人能帮忙吗?

这是我做的代码。

这是型号

Ext.define('VidlyViews.model.Customers', {
extend: 'VidlyViews.model.Base',
fields: [
'name', 'membershipType', 'isSubscribeToNewsLetter', 'birthDate'
]

});

这是商店。

Ext.define('VidlyViews.store.Customers', {
extend: 'Ext.data.Store',
alias: 'store.customers',
model: 'VidlyViews.model.Customers',
autoLoad: true,
proxy: {
type: 'jsonp',
url: 'https://localhost:44300/api/customers',
reader: {
type: 'json',
rootProperty: 'feed.entry'
}
}

});

这是在经典的/src/view/main文件夹中

Ext.define('VidlyViews.view.main.Customers', {
extend: 'Ext.grid.Panel',
xtype: 'customerlist',
requires: [
'VidlyViews.store.Customers'
],
title: 'Customers',
store: {
type: 'customers'
},
columns: [
{ text: 'Customer Name',  dataIndex: 'name', flex: 1 },
{ text: 'Membership Type', dataIndex: 'membershipType', flex: 1 },
{ text: 'Newsletter', dataIndex: 'isSubscribeToNewsLetter', flex: 1 },
{ text: 'Birthdate', dataIndex: 'birthDate', flex: 1 }
],
listeners: {
select: 'onItemSelected'
}

});

提前感谢

我解决了我的问题,希望它能在未来帮助其他人。

我把我的代理改成了这个:

proxy : {
type : 'rest',
actionMethods : {
read : 'GET' 
},
url : 'https://localhost:44300/api/customers',
useDefaultXhrHeader: false,
reader: {
type : 'json',
headers: { 'Accept': 'application/json' },
allDataOptions: {
associated: true,
persist: true
},
rootProperty : 'data'
},
}

我用rest提取数据。rootPropery是数据。在API(ASP.NET(中,我将IhhtpActionResult修改为该

public IHttpActionResult GetCustomers(int start, int limit)

因为在sencha中,您可以获得分页的开始和限制,并在后端使用.Skip((和.Take((。

它看起来像这样:

var customerDtos = customersQuery
.OrderBy(c => c.CustomerId)
.Skip(start)
.Take(limit)
.ToList();

我做的最后一步是返回这样的数据:

return Ok(new { total = customerDtos.Count(), data = customerDtos });

数据在rootProperty中被识别为数据的集合,total是可以在API调用中识别的数据的总数。

我希望它能有所帮助。我花了一整天的时间才弄明白哈哈哈

最新更新