【发布时间】:2012-11-21 14:59:58
【问题描述】:
我有一个这样的商店:
Ext.define('app.store.System', {
extend : 'Ext.data.Store',
model : 'app.model.System',
autoLoad: true,
autoSync: true,
proxy: {
type: 'rest',
format: 'json',
url: '/application/appinfo',
method : "GET",
reader: {
type: 'json',
root: 'System'
},
writer: {
root: 'System',
allowSingle: false
}
}
});
并且我有一个服务端点来处理使用此方法匹配 /application 的请求:
@GET
@Path("/{sysinfo}")
public List<SystemInfo> getSystemInfo() {
if(sysinfo == null){
sysinfo = new SystemInfo();
...initialize
}
List<SystemInfo> resultList = new ArrayList<SystemInfo>();
resultList.add(sysinfo);
return resultList;
}
它似乎工作......当我试图到达 localhost:port/application/sysinfo.json 我得到了这个:
{ [{"address":"...","feeds":["feed1","feed2"] } ] }
这似乎是正确的,但是当我尝试在视图的 init 方法中从存储中读取数据时:
var store = Ext.StoreManager.lookup('System');
var data = [];
store.each(function(record) {
data.push(record.getData());
console.log("record data: ");
console.log(record.getData());
});
console.log(data[0]);
它说它是未定义的,就好像商店是空的一样。我用调试器试了一下,我发现 getSystemInfo() 在视图的 initcomponent 之后被调用 但不幸的是我不知道为什么会这样或如何解决它。有什么想法吗?
感谢您的宝贵时间。
【问题讨论】:
标签: javascript json rest extjs extjs4