我有一个这样的商店:
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之后调用的,但不幸的是我不知道为什么会这样或如何解决它。有任何想法吗?
谢谢你的时间。