Reader/proxy in ext

Source: Internet
Author: User

Last night I found that the use of ready-made jsonstore could not meet my needs, because all the data returned from jsonstore was used for page rendering. For example, if I contained some totalcount and serverstatus attributes, isn't it impossible to map?

I think ext will not be so mentally retarded. I carefully read a reader and probably looked at its usage. The previous store can have a proxy and a reader object.

 

The previous store was written as follows:

VaR store = new Ext. data. jsonstore ({<br/> URL: "Servlet/statusservlet", <br/> root: "datas", <br/> fields: ["ID", "name ", "Step1", "step2", "Step3", "step4", <br/> "status"] <br/> });

 

Now we have written the following:

// Replace it with the form of proxy and reader to define store <br/> var proxy = new Ext. data. httpproxy ({<br/> URL: "Servlet/statusservlet" <br/>}); <br/> var reader = new Ext. data. jsonreader ({<br/> Status: "status", <br/> root: "datas", <br/> fields: [{<br/> Name: "ID" <br/>},{ <br/> name: "name" <br/>},{ <br/> Name: "Step1" <br/>},{ <br/> name: "step2" <br/>},{ <br/> Name: "Step3" <br/>},{ <br/> name: "step4" <br/>},{ <br/> Name: "status" <br/>}] <br/>}); </P> <p> var store = new Ext. data. store ({<br/> Proxy: proxy, <br/> reader: reader <br/> });

 

The returned data is like this:

{"Status": "2", datas: [{"ID": "1", "name": "Site 1", "Step1": "2 ", "step2": "2", "Step3": "2", "step4": "2", "status": "2" },{ "ID ": "2", "name": "Site 2", "Step1": "2", "step2": "2", "Step3": "2 ", "step4": "2", "status": "2" },{ "ID": "3", "name": "Site 3", "Step1 ": "2", "step2": "2", "Step3": "2", "step4": "2", "status": "2 "}, {"ID": "4", "name": "Site 4", "Step1": "2", "step2": "2", "Step3 ": "2", "step4": "2", "status": "2" },{ "ID": "5", "name": "site 5 ", "Step1": "2", "step2": "1", "Step3": "0", "step4": "0", "status ": "0"}]}

 

Using firebug to debug Ext, you can find the status value in the returned data using this method:Reader. jsondata. Status

 

I think there must be more efficient encapsulation methods, but now the problem has been solved and I will remember it later.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.