js构建Data数据

1.简单的GridPanel

View Code
           var data = [

                ['YIN FEI', '2011-06-30 12:45:20.0', 'Unlock','Fix'],

                ['WANG HANPING', '2011-07-04 16:38:55.0', 'Lock','Fix'],

                ['GAO HAIHUA', '2011-07-04 16:38:55.0', 'Lock','Fix'],

                ['LENG JING', '2011-07-04 16:38:55.0', 'Lock','Fix'],

                ['ZHONG WEIXING', '2011-06-30 12:45:20.0', 'Unlock','Temp'],

                ['SONG YUHONG','2011-06-30 12:45:20.0','Unlock','Fix'],

                ['HUANG WEIDONG','2011-06-30 12:45:20.0','Unlock','Fix'],

                ['ZHONG ZHENGQUAN','2011-07-04 16:38:55.0','Lock','Fix'],

                ['CHEN HUIJUN','2011-07-04 16:38:55.0','Lock','Fix'],

                ['LI ZHUOLI','2011-06-30 12:45:20.0','Unlock','Fix']

            ];



                       var store = new Ext.data.ArrayStore({

                           data: data,

                           fields: [

                           { name: 'PERSONINCHARGEONE' }, 

                           { name: 'LOCKDATEONE' },

                           { name: 'LOCKSTATUSONE' },

                           { name: 'FIXSTATUSONE' }

                           

                           ]

                       });

                       var sm = new Ext.grid.CheckboxSelectionModel({handleMouseDown:Ext.emptyFn  });

                       var col = new Ext.grid.ColumnModel([

                       sm,

                       { header:'Person In Charge', dataIndex: 'PERSONINCHARGEONE', sortable: true,align:'center', width: 100 },

                       { header:'Lock/UnLock Date/Time', dataIndex: 'LOCKDATEONE', sortable: true,align:'center', width: 100 },

                       { header:'Lock Status', dataIndex: 'LOCKSTATUSONE', sortable: true,align:'center', width: 100 },

                       { header:'Fix Status', dataIndex: 'FIXSTATUSONE', sortable: true,align:'center', width: 100 }

                       ]);



                   var btnLock = new Ext.Button({

                         text:'Lock',

                         iconCls: 'icon_lock',

                         handler:function()

                         {

                         }

                    });                     

                   var btnUnLock = new Ext.Button({

                         text:'Unlock',

                         iconCls: 'icon_unlock',

                         handler:function()

                         {

                         }

                    }); 



                       var gridArray = new Ext.grid.GridPanel({

                           title:'  List   ',

                           cm: col,

                           sm:sm,

                           store: store,

                           autoScroll: true,

                           columnLines: true,

                           viewConfig: {

                             forceFit:true,

                             columnsText: '显示的列',

                             scrollOffset: 20,

                             sortAscText: '升序',

                             sortDescText: '降序'

                           },

                           bbar:new Ext.PagingToolbar({

                           store:store,

                           pageSize:10,

                           displayInfo:true,

                           items:[btnLock,{xtype:'tbspacer'},{xtype:'tbspacer'},btnUnLock,{xtype:'tbspacer'},{xtype:'tbspacer'}]

                           })

可以看出store中的"field"分别按顺序对应data中的数据,每一个数组 ['YIN FEI', '2011-06-30 12:45:20.0', 'Unlock','Fix']就代表一行数据


2.构建data数据形式

  var data=[[' ',' ',...' '],[' ',' ',...' '],......[' ',' ',...' ']];

如:

现有数据如下

var arr=["00029122---PAPMOSH", "00029014---PEDBJ"];

Store定义如下

        var store = new Ext.data.ArrayStore({

            data:data,

            fields: [

               { name: 'CODE' },

               { name: 'NAME' }

            ]

        });

分析arr中的每一个元素代表这一行数据啊arr[0]="00029122---PAPMOSH"; 00029122对应的是store中的"CODE",PAPMOSH对应store中的"NAME"

最终要的结果var data=[['00029122','PAPMOSH'],['00029014','PEDBJ']]

实现方法如下

            var arr=tempField.split(',');        

            var aStr=new Array();                

            for(var i=0;i<arr.length;i++)

            {

              var split = arr[i].indexOf('---');

                if(i%2==0)

                {

                  aStr.push(arr[i].substring(0,split));

                  aStr.push(arr[i].substring(split+3));

                  data.push(aStr);

                }else

                {

                  aStr=new Array();

                  aStr.push(arr[i].substring(0,split));

                  aStr.push(arr[i].substring(split+3));   

                  data.push(aStr);                              

                }

            }

 

 

 

你可能感兴趣的:(Data)