使用此代码时,我无法获得任何结果......
Ext.define('Teste.view.Main', {
extend: 'Ext.Container',
initialize: function(){
Ext.define('User', {
extend: 'Ext.data.Model',
config: {
fields: ['description', 'discountCode' , 'prodCode'],
proxy: {
type: 'rest',
format:'json',
url : 'http://localhost:8080/stcws/resources/com.database.productcode/'
}
}
});
var store = new Ext.create('Ext.data.Store', {
model: 'User'
});
store.load();
console.log(store.getCount());
}});
但如果我拿出来
format:'json',
我得到了一个XML响应,我做错了什么?
答案 0 :(得分:2)
要使用'Rest'代理并获取Json响应,我们只需要添加到代理:
headers: {
'Accept' : 'application/json'
},
然后拿出......
format:'json',
答案 1 :(得分:0)
使用Json Reader读取服务器响应。
http://docs.sencha.com/touch/2-0/#!/api/Ext.data.reader.Json
<强>尝试:强>
proxy: {
type: 'ajax',
url : 'users.json',
reader: {
type: 'json'
}
}
或
proxy: {
type: 'ajax',
url : 'users.json',
reader: {
type: 'json'
model: 'User'
}
}