好吧,这就是正在发生的事情,我有一个列表,如果我使用商店上的 data 属性对数据进行硬编码,但是当我尝试使用代理时没有显示任何内容...代理设法发送数据和从服务器接收数据,但列表仍然拒绝显示任何内容......
这是视图:
Ext.define('MyApp.view.myListView', {
extend: 'Ext.List',
xtype: 'myListView',
requires: ['MyApp.store.myListStore'],
config: {
title: 'American Companies',
grouped: false,
itemTpl: '{company} {contact}',
store: 'myListStore',
onItemDisclosure: true
}});
该模型:
Ext.define('MyApp.model.myListModel', {
extend: 'Ext.data.Model',
config: {
fields: ['company', 'contact']
}
});
商店:
Ext.define('MyApp.store.myListStore', {
extend: 'Ext.data.Store',
requires: ['MyApp.model.myListModel', 'MyApp.proxy.myListProxy'],
config: {
model: 'MyApp.model.myListModel',
proxy: 'searchProxy',
autoLoad: true,
grouper: {
groupFn: function (record) {
return record.get('contact').substr(0, 1);
}
}
}
});
代理:
Ext.define('MyApp.proxy.myListProxy', {
extend: 'Ext.data.proxy.Ajax',
alias: 'proxy.searchProxy',
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
callbackKey: 'callback',
type: 'json',
config: {
model: 'MyApp.model.myListModel',
url: '/myUrl that works',
reader: {
type: 'json',
rootProperty: 'data' // E.g. {results: [{id: 123, description: 'some text'}, {...}]},
}
},
read: function (operation, callback, scope) {
Ext.Ajax.request({
url: '/myUrl that works',
//success: passFn, // function called on success
failure: failFn,
jsonData: {
"data": {
"fields": ["company", "contact"],
}
}
});
},
filterParam: undefined,
/**
* NOTE: so I can add other params as I needed the params for a search request
* You could use extraParams instead
*/
buildRequest: function(operation) {
var request = this.callParent(arguments);
var params = request.getParams();
// var searchRequest = getSearchRequest(); // helper method
// if (searchRequest) {
// Ext.apply(params, searchRequest);
// }
return request;
}
});
function failFn(msg) {
Ext.Msg.alert('Ajax Error', msg);
}