如何根据 get 请求创建多个 JSON 存储?
假设我在客户端使用 extjs4 构建了这个 Web 应用程序,在服务器端使用 Zend 框架操作控制器。我在服务器端有一组数组,它们可以作为 JSON 输出到客户端。当我只想创建一个存储时,通常的方式是这样工作的:
Ext.define('MA.store.AdminResources', {
extend : 'Ext.data.Store',
fields : [ {
name : 'id'
}, {
name : 'name'
} ],
autoLoad : true,
proxy : {
type : 'ajax',
url : './account/adminresources',
reader : {
type : 'json'
//,root : 'users'
}
}
});
如果我想从单个 http 创建多个 JSON 存储怎么办向服务器请求? 该服务器不会接收每个商店的远程代理请求,并且将为所有商店完成一个请求。 以下是服务器返回的 JSON 的示例:
{
"adminsettings"{"userid":3333,"primaryemail":"[email protected]","firstname":"","middlename":null}
,"countries":{"AD":"Andorra","AE":"UnitedArabEmirates","AF":"Afghanistan"...}
,"languages":{"aa":"Afar","ab":"Abkhazian","ace":"Achinese","ach":"Acoli"...
}}
How can JSON stores for adminsettings,countries, languages be create with just one http request to the server? 也许我需要定义 1 个代理和 3 个读取器?!
Lets suppose I have this web application built using extjs4 in my client-side and a Zend framework action controller in server-side. I have array of arrays in server-side that they could be output as JSON to the client.when i want to create only one store,usual way is working like this:
Ext.define('MA.store.AdminResources', {
extend : 'Ext.data.Store',
fields : [ {
name : 'id'
}, {
name : 'name'
} ],
autoLoad : true,
proxy : {
type : 'ajax',
url : './account/adminresources',
reader : {
type : 'json'
//,root : 'users'
}
}
});
what if i wanted to create multiple JSON stores from just A single http request to the server?
this server will not receive a remote proxy request per store and one request will be done for ALL stores.
Here is an example of my JSON which is returned by server:
{
"adminsettings"{"userid":3333,"primaryemail":"[email protected]","firstname":"","middlename":null}
,"countries":{"AD":"Andorra","AE":"UnitedArabEmirates","AF":"Afghanistan"...}
,"languages":{"aa":"Afar","ab":"Abkhazian","ace":"Achinese","ach":"Acoli"...
}}
How can JSON stores for adminsettings,countries,languages be created with just one http request to the server?
perhaps i need to define one proxy and 3 readers?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如您在文档中看到的,您可以定义不带代理的存储:
然后很容易发出 ajax 请求和 onSuccess 手动加载数据:
如下所示:
As you can see in the documentation you can define store without proxy:
then It's easy to make an ajax request and onSuccess to load data manualy:
Something like this:
在阅读 extjs 学习中心网格常见问题解答时,我找到了确切的问题和我的问题的答案。以下是问题和答案:
使用一个 AJAX 请求加载多个商店?
还有一个使用 XML 的示例 此处
将数据从作为单个 http 请求的一部分返回的单个 json 字符串显示到多个数据存储。
选项 1:(查看此帖子)
选项 2:
While reading on extjs learning center grid faq i found the exact question and answer to my question. Here is the question and the answer:
Load multiple stores with one AJAX request?
There is also an example using XML here
display data to multiple data stores from a single json string that a returned as part of a single http request.
Option 1: (see this thread)
Option 2: