Ext.data.proxy 中jsonp方式,获取数据的问题---初学者的问题
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
}
}
把STORE改成:
proxy: {
type: 'jsonp',
url : 'http://localhost:4529/Messagemg/message_index.aspx',
callbackKey: 'cbackf',
reader : {
type : 'json',
root : 'info',
implicitIncludes:true,
totalCount : 'total'
}
可是问题依旧,问题出在那里呢?
josephSC:我修改后还是不行!
[其他解释]
是JSON格式不对,还是调用方法有问题,从网络监控可以看到请求发出,应答也回来了,理论上说问题是出在接收和JSON数据解析上!!!
[其他解释]
二楼给的连接的方法,是为了自己定义callback类的名字。也就是把默认的"callback"替换成了你现在用的"cbackf",所以要用到"callbackKey"。如果是默认的"callback"就不需要"callbackkey"。因为jsonP和其他请求不同,它是跨域的。所以必须在服务器端支持callback
你现在确定已经能够成功在网页得到完整的json?
如果是,那你的alert后跳出的对话框是空白还是“undefined"还是"Object [object Object] "?
你用的监控软件是firebug吧,如果是firebug有没有报其他错?
store.load的callback的格式为function(records, options, success)比如:
me.store.load({
callback: function(records, operation, success) {
alert(records); //试一下这样提示框里显示的是什么?
}
});