ExtJS 网格不显示剩余数据
ExtJS Grid Not Displaying Rest Data
我创建了一个迷你 EXTJS 应用程序,定义了模型、商店和网格。我已经验证商店正在运行,因为我可以使用 Chrome 调试工具来创建实例和查看数据。但是,当我尝试在网格中显示数据时,它永远不会显示。
这是 app.js 的代码:
Ext.application({
launch: function () {
Ext.define('Companies', {
extend: 'Ext.data.Model',
fields: ['id', 'link', 'name']
});
Ext.define('CompaniesStore', {
extend: 'Ext.data.Store',
model: 'Companies',
storeId: 'cStore',
autoLoad: true,
proxy: {
type: 'rest',
url: 'http://corky52547.somee.com/Service1.svc/Companies'
}
});
Ext.create('Ext.container.Viewport', {
name : "viewPort2",
layout: 'fit',
renderTo: Ext.getBody(),
items: [
{
title: 'Bill Reminder Web'
},
{
xtype: 'grid',
title: 'Bills',
height: 100,
width: 100,
columns: [
{text: 'ID', width: 100, dataIndex: 'id'},
{text: 'Link', flex: 1, dataIndex: 'link'},
{text: 'Name', width: 200, dataIndex: 'name'}
],
store: Ext.create('CompaniesStore',{})
}
]
});
}
});
更新:
我现在可以获取要显示的数据,但没有主题。如何更新主题?
CORS(跨源请求)正在阻止对域的请求。
Layout Fit 也导致了一些问题。
要使 CORS 正常工作,您需要添加
Access-Control-Allow-Origin: *
否则,你可以使用像cors-anywhere
这样的中间件代理
字段名称等小错误应与它们在响应中可用的确切大小写相匹配。
这是一个有效的 POC 代码:
Ext.application({
name: "Application",
launch: function () {
Ext.define('Companies', {
extend: 'Ext.data.Model',
fields: ['ID', 'Link', 'Name']
});
Ext.define('CompaniesStore', {
extend: 'Ext.data.Store',
model: 'Companies',
storeId: 'cStore',
autoLoad: true,
proxy: {
type: 'rest',
url: 'https://cors-anywhere.herokuapp.com/http://corky52547.somee.com/Service1.svc/Companies'
}
});
Ext.create('Ext.container.Viewport', {
name: "viewPort2",
renderTo: Ext.getBody(),
items: [{
title: 'Bill Reminder Web'
}, {
xtype: 'grid',
title: 'Bills',
flex: 1,
columns: [{
text: 'ID',
width: 100,
dataIndex: 'ID'
}, {
text: 'Link',
flex: 1,
dataIndex: 'Link'
}, {
text: 'Name',
width: 200,
dataIndex: 'Name'
}],
store: Ext.create('CompaniesStore', {})
}]
});
}
});
这里正在工作 fiddle: https://fiddle.sencha.com/#view/editor&fiddle/2gbc
我创建了一个迷你 EXTJS 应用程序,定义了模型、商店和网格。我已经验证商店正在运行,因为我可以使用 Chrome 调试工具来创建实例和查看数据。但是,当我尝试在网格中显示数据时,它永远不会显示。
这是 app.js 的代码:
Ext.application({
launch: function () {
Ext.define('Companies', {
extend: 'Ext.data.Model',
fields: ['id', 'link', 'name']
});
Ext.define('CompaniesStore', {
extend: 'Ext.data.Store',
model: 'Companies',
storeId: 'cStore',
autoLoad: true,
proxy: {
type: 'rest',
url: 'http://corky52547.somee.com/Service1.svc/Companies'
}
});
Ext.create('Ext.container.Viewport', {
name : "viewPort2",
layout: 'fit',
renderTo: Ext.getBody(),
items: [
{
title: 'Bill Reminder Web'
},
{
xtype: 'grid',
title: 'Bills',
height: 100,
width: 100,
columns: [
{text: 'ID', width: 100, dataIndex: 'id'},
{text: 'Link', flex: 1, dataIndex: 'link'},
{text: 'Name', width: 200, dataIndex: 'name'}
],
store: Ext.create('CompaniesStore',{})
}
]
});
}
});
更新:
我现在可以获取要显示的数据,但没有主题。如何更新主题?
CORS(跨源请求)正在阻止对域的请求。 Layout Fit 也导致了一些问题。
要使 CORS 正常工作,您需要添加
Access-Control-Allow-Origin: *
否则,你可以使用像cors-anywhere
这样的中间件代理字段名称等小错误应与它们在响应中可用的确切大小写相匹配。
这是一个有效的 POC 代码:
Ext.application({
name: "Application",
launch: function () {
Ext.define('Companies', {
extend: 'Ext.data.Model',
fields: ['ID', 'Link', 'Name']
});
Ext.define('CompaniesStore', {
extend: 'Ext.data.Store',
model: 'Companies',
storeId: 'cStore',
autoLoad: true,
proxy: {
type: 'rest',
url: 'https://cors-anywhere.herokuapp.com/http://corky52547.somee.com/Service1.svc/Companies'
}
});
Ext.create('Ext.container.Viewport', {
name: "viewPort2",
renderTo: Ext.getBody(),
items: [{
title: 'Bill Reminder Web'
}, {
xtype: 'grid',
title: 'Bills',
flex: 1,
columns: [{
text: 'ID',
width: 100,
dataIndex: 'ID'
}, {
text: 'Link',
flex: 1,
dataIndex: 'Link'
}, {
text: 'Name',
width: 200,
dataIndex: 'Name'
}],
store: Ext.create('CompaniesStore', {})
}]
});
}
});
这里正在工作 fiddle: https://fiddle.sencha.com/#view/editor&fiddle/2gbc