這是怎麼回事,我有一個列表,我工作得很好,如果我硬編碼數據使用商店的數據屬性,但是當我嘗試使用代理不顯示什麼...代理管理髮送數據&從服務器接收數據,但仍列表拒絕說明了什麼?Sencha2代理檢索數據,但列表不顯示
這是視圖:
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);
}
你爲什麼要重寫代理中的'read'方法? – SachinGutte 2013-05-04 10:49:02
事實上,這是它爲我工作的方式......沒有閱讀功能,我無法做到這一點,以及事實上沒有ajax請求..單獨的代理沒有發送任何數據,我是新來的這個哈哈 – martuanez 2013-05-05 13:48:37
結帳回答下面。我自己嘗試過,並且工作。 :D – SachinGutte 2013-05-05 13:56:19