Model:
Ext.define('ecms.view.message.messageindexmodel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'source', type:'string' },
{ name:'type', type:'string' },
{ name:'title', type:'string' },
{ name:'url',type:'string' }
]
});
Store:
Ext.define('ecms.view.message.messageindexstore', {
extend: 'Ext.data.Store',
model: 'ecms.view.message.messageindexmodel',
autoLoad: false,
remoteSort: true,
remoteFilter: true,
pageSize: 30,
autoSync: false,
sorters:[{
property:'source',
direction:'ASC'
}],
proxy: {
type: 'jsonp',
url : 'http://localhost:4529/Messagemg/jss.js',
reader: {
type: 'json',
implicitIncludes:true,
record : 'info'
}
}
});
调用:
var me = this;
me.store = Ext.create('ecms.view.message.messageindexstore');
me.store.load({
callback: function() {
var user = me.store.first();
alert(user);
}
});
JS:
var info={"info":[{"source":"1","type":"系统公告","title":"dddddddd (2012-01-26)","url":"http://localhost:4529/Messagemg/message_edit_release.aspx?id=74"},{"source":"1","type":"系统公告","title":"dddddddd (2012-01-26)","url":"http://localhost:4529/Messagemg/message_edit_release.aspx?id=74"}]}
跟踪请求已发出,就是读不出任何内容,显示为空
------最佳解决方案--------------------
在proxy的reader里没有定义root:
proxy: {
type: 'jsonp',
url : 'http://localhost:4529/Messagemg/jss.js',
reader: {
type: 'json',
implicitIncludes:true,
root : 'info' //感觉问题可能在这里,试试把你的record 换成root
}
}
------其他解决方案--------------------
数据格式错了,看红色部分,还需要用Response.Write输出info
string cb = Request.Params.Get("cbackf");
string info = "{\"success\":true,\"total\":2,\"info\":{[{\"source\":\"1\",\"type\":\"系统公告\",\"title\":\"dddddddd (2012-01-26)\",\"url\":\"http://localhost:4529/Messagemg/message_edit_release.aspx?id=74\"},{\"source\":\"1\",\"type\":\"系统公告\",\"title\":\"dddddddd (2012-01-26)\",\"url\":\"http://localhost:4529/Messagemg/message_edit_release.aspx?id=74\"}]}}";
info = cb + "(" + info + ")";
Response.Write(info);
------其他解决方案--------------------
参考http://www.sencha.com/forum/showthread.php?155122-Proxy-not-working-with-type-jsonp-!!!
把JSON输出放到一个ASPX中
String cb = Request.Params.Get("cbackf");
info = "{\"success\":true,\"total\":2,\"info\":{[{\"source\":\"1\",\"type\":\"系统公告\",\"title\":\"dddddddd (2012-01-26)\",\"url\":\"http://localhost:4529/Messagemg/message_edit_release.aspx?id=74\"},{\"source\":\"1\",\"type\":\"系统公告\",\"title\":\"dddddddd (2012-01-26)\",\"url\":\"http://localhost:4529/Messagemg/message_edit_release.aspx?id=74\"}]}}";
info = cb + "(" + info + ")";