ExtJs4 保存自定义布局到服务器端

                                state = [];
                                var portal = Ext.getCmp("app-portal");
                                //拿到PortalColumn
                                var items = portal.items;
                                for(var i=0;i<items.getCount();i++) {
                                    var c = items.get(i);
                                    //将PortalColumn当中的每一个portlet的状态记录下来
                                    c.items.each(function(item, index) {
                                        var st = {id:item.id, col:i, index:index};
                                        state.push(st);
                                    });
                                };
                                alert(Ext.JSON.encode(state));



handler: function() {
                                var portal = Ext.getCmp("app-portal");
                                //PortalColumn
                                var items = portal.items;

                                //将元素全部清除
                                for (var i = 0; i < items.getCount(); i++) {
                                    var c = items.get(i);  
                                    c.items.each(function(portlet){  
                                        c.remove(portlet, false);  
                                    });  
                                }
                                //根据保存的状态重新布局          
                                for (var i = 0; i < state.length; i++) {
                                    var st = state[i];
                                    items.get(st.col).add(Ext.getCmp(st.id));
                                }
                            }

你可能感兴趣的:(ext)