ExtJS 4 套阅读器

发布于 2025-01-03 00:41:57 字数 859 浏览 4 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

始终不够爱げ你 2025-01-10 00:41:57

您最好使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文