面板重叠,同时动态加载它们

时间:2012-05-29 07:53:37

标签: forms extjs panel

我在工具栏上有几个选项卡,每个选项卡都有单独的处理程序,我调用了每个处理程序的单独功能。代码如下

Ext.define('myco.view.User', {
    extend: 'Ext.Container',
    config: {
        scrollable: true,
        items: [{
                xtype: 'panel',
                id: 'User'
            },

            {
            docked: 'top',
            xtype: 'toolbar',
            items: [{
                text: 'My Profile',
                handler: function() {
                    var panel = Ext.getCmp('User'),
                        tpl = new Ext.XTemplate([
                        '<div class="demo-weather">',
                            '<tpl for=".">',
                                '<div class="day">',
                                    '<div class="date">{username}</div>',
                                    '<tpl for="weatherIconUrl">',
                                        '<img src="{value}">',
                                    '</tpl>',
                                    '<span class="temp">{tempMaxF}&deg;<span class="temp_low">{tempMinF}&deg;</span></span>',
                                '</div>',
                            '</tpl>',
                        '</div>'
                    ]);

                    panel.getParent().setMasked({
                        xtype: 'loadmask',
                        message: 'Loading...'
                    });

                    Ext.Ajax.request({
                        url: 'http://localhost:8000/api/myapp/user/',
                        method:'GET',
                        callbackKey: 'callback',
                        defaultHeaders : 'application/json',
                        params: {
                            //key: '23f6a0ab24185952101705',
                            //q: '94301', // Palo Alto
                            format: 'json',
                            //num_of_days: 5
                        },
                        success : function(response, opt) {
                                    dataarray = Ext.decode(response.responseText);
                                    weather=dataarray.objects;
                                    panel.updateHtml(tpl.applyTemplate(weather))
                                    panel.getParent().unmask();
                                    },
                        failure : function(response, opt) {
                                     Ext.Msg.alert('Failed', response.responseText);
                                     panel.getParent().unmask();
                                    }       


                    });
                }
            },
            {
                 text:'login',
                 handler: function() {
                     var main = new Ext.Panel({  
                                   title: 'My first panel', //panel's title  
                                   fullscreen: true,
                                   //the element where the panel is going to be inserted 
                                   //html: 'Nothing important just dummy text' //panel's content  
                                   items:[
                        {
                            xtype: 'fieldset',
                            title: 'Login',
                            items: [
                                {
                                    xtype: 'textfield',
                                    label: 'Username',
                                    name:   'username',
                                    id  :  'username'
                                },
                                {
                                    xtype: 'passwordfield',
                                    label: 'Password',
                                    name:  'password',
                                    id   :  'password'
                                }
                            ]
                        },
                        {
                            xtype: 'button',
                            text: 'Send',
                            ui: 'confirm',

                            handler: function() {}

                        }
                    ]
                                   });  
                 panel.add(main);
                 alert('test');
                 }
            }
            ]
        }]
    }
});

现在,当我点击标签时,前一个面板将不会被清除,数据将在那里重叠.....就像当我点击我的个人资料个人资料被列在那里,之后当我点击登录个人资料+登录时两者都将是加载一个重叠另一个...

1 个答案:

答案 0 :(得分:1)

您应该使用Ext.tab.Panel,将您的个人资料和登录面板定义为父TabPanel的项目,切换将由ExtJS处理。您可以使用Panel的 activate 事件添加自定义逻辑,以便在激活标签时执行。