首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ext js组件查询

Ext js组件查询
EN

Stack Overflow用户
提问于 2012-12-13 10:53:15
回答 2查看 11.8K关注 0票数 1

我正在用extjs4 + yii框架开发网站。我使用一个边框布局作为一个视口。在里面,我使用手风琴布局和显示主页。在主页上有一个登录窗口,我想在连接完成后隐藏。我怎么才能移除这扇窗户。这是我的密码:--

代码语言:javascript
复制
1)Viewport.js:-
Ext.define('AM.view.Viewport', {
    extend: 'Ext.container.Viewport',
    layout: 'border',
    id:'vp',
    border: 5,
    style: {
        borderColor: 'red',
        borderStyle: 'solid'
    },
    requires: [
               'AM.view.header.Header',
               'AM.view.login.Login',
               'AM.view.wordOfDay.WordOfDay',
               'AM.view.weather.Weather',
               'AM.view.poll.Poll',
               'AM.view.qod.QOD',
               'AM.view.history.History',
               'AM.view.qod.LastQuestion'
              ],


    items: [
    {
        region:'north',
        xtype: 'headerHeader',
        margins:5,
        height:70,
        //html:'<h1>Welcome</h1>',
    },
    {
    /*  title:'West',
        region:'west',
        margins:'0 5 0 5',
        flex:.3,
        collapsible:true,
        split:true,
        titleCollapse:true,
    */  

    //  title:'Main menu',

        region:'west',
        margins:'0 5 5 5',
        flex:.3,
        //collapsible:true,
        //titleCollapse:true,
        layout:'accordion',
        layoutConfig:
        {
                animate:false,
                multi:true
        },
        items:[
        {
            title:'wordOfDay',
            xtype:'wod' 
        },
        {
            title:'weather Information',
            xtype:'weather' 
        },
        {
            title:'poll of the day',
            xtype:'poll'
        },
        {
            title:'questionOfDay',
            xtype:'questionOfDay'
        }
        ]//end if items

    },
    {
        //title:'center',
        region:'center',
        html:'center region'
    },
    {
    /*  //title:'East',
        xtype:'loginLogin',
        region:'east',
        margins:'0 5 0 5',
        width:200,
        //collapsible:true,
        //collapsed:true,
    */
        region:'east',
        margins:'0 5 0 5',
        flex:.3,
        //collapsible:true,
        //titleCollapse:true,
        layout:'accordion',
        layoutConfig:
        {
                animate:false,
                multi:true
        },
        items:[
        {
            title:'Login Window',
            xtype:'loginLogin'
        },       
        {
            title:'QuestionOfDay',
            xtype:'questionOfDay'
        },
        {
            title:'Last Question And its answer',
            xtype:'lastQusetion'
        },
        {
            title:'This Day In a History',
            xtype:'history'
        }
        ]//end if items
    },
    {
        //title:'South',
        region:'south',
        margins:'0 5 5 5',
        flex:.1,
        html:'<h6 align="center">Footer</h6>',
        split:false
    },//mainMenu   // used mainMenu when you are using mainMenu variable
    ]//end if items
});//End of view port

2)Login.js :-- this is the login view page
Ext.define('AM.view.login.Login',
{
        extend:'Ext.form.Panel',
        id:'lg',
        alias:'widget.loginLogin',
        bodyStyle:'padding:5px 5px 0',
        title:'Login Window',
        hidden:false,
        height: 150,
        //items:
        //[
         //{
             //xtype:'form',
             border:3,
             items:[
                    {
                        xtype:'textfield',
                        fieldLabel:'Key In',
                        name:'uname',
                        //width:'10px',
                        anchor:'100%',
                        //flex:2,
                        //labelAlign:'top',               
                        //  cls:'field-margin',
                        allowBlank:false,
                        //minLength:6,
                        //draggable:true,
                    },
                    {
                        xtype:'textfield',
                        fieldLabel:'Key',
                        //width:'20px',
                        flex:6,
                        //labelAlign:'top',
                        name:'pass',
                        inputType:'password',
                        allowBlank:false,
                        minLength:6,
                        anchor:'100%',

                    },
                    {
                        xtype:'button',
                        formBind: true,
                        fieldLabel:'Keylogin',
                        action:'loginAction',
                        text:'login',
                        //width:'20px',
                        flex:6,
                        //labelAlign:'top',

                        anchor:'100%',

                    }
                    ],  
         //}],//end of items
});//End

( 3)这里是控制器文件中的一些代码

代码语言:javascript
复制
authenticateUser:function(button)
{   
    console.log('enter');
    var obj = Ext.ComponentQuery.query('#vp');

    obj[0].remove('lg');
}    

代码正在执行,但并不隐藏登录window.please给我的建议。提前谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-12-13 12:00:48

Ext.ComponentQuery.query()方法总是返回一个对象数组,因此将代码从var obj = Ext.ComponentQuery.query('#vp');更改为var obj = Ext.ComponentQuery.query('#vp')[0];,这将给出数组中的第一个元素。您需要检查第一个元素是否为空。

票数 3
EN

Stack Overflow用户

发布于 2012-12-14 05:19:15

首先,你的窗口不是窗口,而是面板,对吗?正确的。其次,使用remove方法是一个容器删除它的子项。例: MyPanel.remove( subpanel );-这将移除子面板http://docs.sencha.com/ext-js/4-1/source/AbstractContainer.html#Ext-container-AbstractContainer-method-remove

第三,ComponentQuery.query(选择器)返回一个对象数组,即使只找到一个对象。如何使用它,以及对于不同的选择器类型,请阅读docs:http://docs.sencha.com/ext-js/4-1/#!/api/Ext.ComponentQuery

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13858292

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档