ExtJS 4 套阅读器
我有一个 JSON,被应用程序中的其他部分使用了几次。 为了避免不必要的调用,我想获取它,而不是只使用它 哪里需要。
问题是,JSON 可以包含不同部分的不同部分, 这就是为什么我需要使用 root 属性。
我需要什么: - 将获取它的代理(一个为所有) - 每个部分的阅读器,因为它们使用不同的根 - 存储不同的部分
代理:
var myProxy = new Ext.data.proxy.Ajax({
url: "static/data/myData.json"
});
var operation = new Ext.data.Operation({
action: "read"
});
myProxy.read(operation);
某些部分:
// try to create custom reader with appropriate root
var reader = new Ext.data.reader.Json({
root: "table1"
});
// set reader to proxy
myProxy.setReader(reader);
// create store
Ext.create("Ext.data.Store", {
storeId: "MyStore",
model: "MyModel",
autoLoad: true
});
// set proxy to store
Ext.data.StoreManager.lookup("MyStore").setProxy(proxy);
当然,这是行不通的。我必须怎样做?
I have a JSON that used by other parts in application a few times.
To avoid unneeded calls, I want to fetch it ones, and than only use it
where it needs.
the issue is, that JSON cantains a different sections for different parts,
thats why I need to use root
property.
What I need:
- Proxy that will fetch it ones (One for all)
- Reader for each part, 'cause they use different root
- Store for different parts
Proxy:
var myProxy = new Ext.data.proxy.Ajax({
url: "static/data/myData.json"
});
var operation = new Ext.data.Operation({
action: "read"
});
myProxy.read(operation);
Some Part:
// try to create custom reader with appropriate root
var reader = new Ext.data.reader.Json({
root: "table1"
});
// set reader to proxy
myProxy.setReader(reader);
// create store
Ext.create("Ext.data.Store", {
storeId: "MyStore",
model: "MyModel",
autoLoad: true
});
// set proxy to store
Ext.data.StoreManager.lookup("MyStore").setProxy(proxy);
Of course, this doesn't work. How I have to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您最好使用 AJAX 获取来获取 JSON,将其缓存在某个变量中,然后使用商店的
loadData
方法根据需要填充每个商店。loadData
允许您手动添加记录,而无需访问远程数据源。这将为您提供更严格的控制,而无需处理代理;只是读者和商店。You'd be better off using a AJAX fetch to get the JSON, caching it in some variable and then using your store's
loadData
method to fill each store as needed.loadData
lets you manually add records without going to the remote data source. That'll give you tighter control without having to deal with the proxies; just the readers and stores.