1.Ext.onReady(function(){ 2.//header也就是你应该从后台取回的表头数据,现在写死在了这里 3. var headers = [{name: 'company',header:'Company'},{name: 'price',header:'Price'},{name: 'change',header:'change'}] 4. var store = new Ext.data.SimpleStore({ 5. fields: headers 6. }); 7. var columns = []; 8. Ext.each(headers,function(h){ 9. columns.push({ 10. header:h.header, 11. dataIndex:h.name 12. }); 13. }); 14. 15. var grid = new Ext.grid.GridPanel({ 16. store: store, 17. columns: columns, 18. stripeRows: true, 19. height:350, 20. width:600, 21. title:'Array Grid' 22. }); 23. 24. grid.render('grid'); 25.});
?上面从后台取表头的时候应该用同步方法调用后台,而不是用异步,如果用异步的话,会出现你还没拿到后台的表头数据就实例化了grid.
给你个同步请求的方法:
1.var syncRequest = function(url) { 2. var conn = Ext.lib.Ajax.getConnectionObject().conn; 3. try { 4. conn.open("GET", url, false); 5. conn.send(null); 6. } catch (e) { 7. Ext.Msg.alert('info','error'); 8. return false; 9. } 10. return Ext.decode(conn.responseText); 11. } 12.//把上面的headers改为 13.var headers = syncRequest(url); 14.后台的返回数据为headers的内容就行啦
?