Precautions for dynamically generating grid columns and store based on data transmitted in the background

Source: Internet
Author: User

1. Do not request columns dynamically displayed in the background in the initcomponent method of the grid, because the callparent () method will be prior to the background of your requestCodeExecution, so when you call the parent class method, your columns and store are not created yet, this will be wrong.

The method of the grid should be put into the method of request background parameters when the grid is created, and then the data returned by the request is encapsulated in the initcomponent columns and store, this ensures that columns and store are created before the parent class method is called.

for example, the Class Name of the created grid is Ext. App. wris. Rain. rturesultlistpanel. I want to create the grid when I click the button. The call code is as follows:
listeners :{< br/> CLICK: {<br/> FN: function (OBJ, E, OP) {<br/> If (! Res) {<br/> raincontroller. searchtimecolumnrain (12, function (result, e) {<br/> If (E. status) {<br/> res = result; <br/> var resultpanel = ext. create ('ext. app. wris. rain. rturesultlistpanel '); <br/>}< br/> }); <br/>}

Here, raincontroller. searchtimecolumnrain is the method corresponding to the background, and RES is a defined global variable. If there is a way to not define the global variables, you can call them in the initcomponent method of Ext. App. wris. Rain. rturesultlistpanel.

 

2. Do not concatenate strings to encapsulate columns and store fields. You should write them as follows:

VaR columns = []; <br/> var Col ={}; <br/> var fields = []; <br/> var field = {}; <br/> for (VAR I = 0; I <res. length; I ++) {<br/> var type = ''; <br/> If (" int "= res [I]. columntype | "float" = res [I]. columntype) {<br/> type = 'number'; <br/>} else {<br/> type = 'string '; <br/>}</P> <p> Col = {<br/> text: res [I]. columndisname, <br/> dataindex: res [I]. columnname <br/>}; <br/> columns. push (COL); </P> <p> If (type = '') {<br/> type = 'auto '; <br/>}</P> <p> Field = {<br/> name: res [I]. columnname, <br/> type: Type <br/>}; </P> <p> fields. push (field); <br/>}

columns is a set of column models, and COL is each column

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.