0
我是Sencha的新手。我在網絡中獲取數據的響應,但數據未加載到網格中。如果我嘗試在代理中使用靜態數據,網格加載這些值。請幫助我。未能在網格視圖中顯示商店中的Json數據(使用Sencha框架)
Response:
[{"name":"Thanos","email":"[email protected]","phone":"5555555555"},{"name":"Spider Man","email":"[email protected]","phone":"2125555555"},{"name":"Daredevil","email":"[email protected]","phone":"2125555555"},{"name":"The Maker","email":"[email protected]","phone":"2125555555"},{"name":"Rocket","email":"[email protected]","phone":"5555555555"},{"name":"Galactus","email":"[email protected]","phone":"5555555555"},{"name":"Silver Surfer","email":"[email protected]","phone":"5555555555"},{"name":"Hulk","email":"[email protected]","phone":"2125555555"},{"name":"Squirrel Girl","email":"[email protected]","phone":"2125555555"},{"name":"Thor","email":"[email protected]","phone":"5555555555"}]
Store:
Ext.define('CRUD.store.Personnel', {
extend: 'Ext.data.Store',
alias: 'store.personnel',
fields: ['name', 'email', 'phone'],
// data: [
// { name: 'Jean Luc', email: "[email protected]", phone: "555-111-1111" },
// { name: 'Worf', email: "[email protected]", phone: "555-222-2222" },
// { name: 'Deanna', email: "[email protected]", phone: "555-333-3333" },
// { name: 'Data', email: "[email protected]", phone: "555-444-4444" }
// ],
proxy: {
headers: {
"Content-Type": "application/json"
},
type: 'jsonp', //cross domain calls - json parser
url: 'http://localhost:8080/list',
reader: {
type: 'json',
},
listeners: {
load: function(store, records, success, operation, data) {
// Ext.each(records, function(rec) {
// Ext.Msg.alert("test")
// console.log(rec.get('name'));
// });
console.log(JSON.stringify(success));
},
exception: function(proxy, response, operation) {
// exception handling
console.log(response);
}
}
},
// proxy: {
// type: 'memory',
// reader: {
// type: 'json',
// }
// },
autoLoad: true,
});
View: List.js
/**
* This view is an example list of people.
*/
Ext.define('CRUD.view.main.List', {
extend: 'Ext.grid.Panel',
xtype: 'home',
requires: [
'CRUD.store.Personnel'
],
title: 'Heroes',
store: {
type: 'personnel'
},
columns: [
{ text: 'Name', dataIndex: 'name', flex: 1 },
{ text: 'Email', dataIndex: 'email', flex: 1 },
{ text: 'Phone', dataIndex: 'phone', flex: 1 }
],
listeners: {
select: 'onItemSelected',
},
});
感謝您的回覆。我已經將響應轉換爲jsonp格式。它的工作。非常感謝。我已經在節點js中改變了這種輸出響應:res.jsonp(result) –