antd design Menu菜单下拉回调以及下拉列表时只能显示一个列表,其余关闭

我做的是一个显示全国省市区的下拉列表:如下图
这里写图片描述
这个下拉列表是三层嵌套的下拉列表,统计列表不能同时打开,一次只能点开一个。点击下拉时触发函数获得下一层级的下拉数据。
代码如下:

  render(){
let city=this.state.cityList.map(itemss=>(
             <SubMenu
                 key={itemss.id}
                 title={<span ><Icon type="team" /><span className="nav-text">{itemss.name}</span></span>}
                 onTitleClick={this.getCountryList.bind(this,itemss.id,itemss.name)}
             >
                 {
                     this.state.countryList.map(citem=>(
                        <Menu.Item key={citem.id}> <span onClick={this.checkedItem.bind(this,citem.id,citem.name)} >{citem.name}</span></Menu.Item>
                     ))
                 }
             </SubMenu>

         ));
        const { startValue, endValue, endOpen } = this.state;
        return(
            <div className="div-body">
                <div className="div-page">
                    <div className="div_query ">
                        <Layout>
                                <div className="" />
                            <Sider
                                collapsed={this.state.collapsed}
                                style={{backgroundColor:'#FFFFFF'}}
                                className=""
                                onCollapse={this.onCollapse}
                                openKeys={this.state.openKeys}--->根据this.state.openKeys的值去对应SubMenu的key值 从而展开此列表。
                            >
                                 <Menu theme="" mode={this.state.mode}
                                       defaultSelectedKeys={['6']}
                                       openKeys={this.state.openKeys}
                                 >
                                   <SubMenu
                                        key="全国"
                                        title={<span><Icon type="user" /><span className="nav-text">全国</span></span>}
                                        onTitleClick={this.getProvinceList}
                                    >
                                        {
                                            this.state.provinceList.map((items,i)=>

                                                 <SubMenu
                                                    key={items.id}
                                                    title={<span ><Icon type="team" /><span className="nav-text">{items.name}</span></span>}
                                                    onTitleClick={this.getCity.bind(this,items.id,items.name,0)}--->onTitleClick---》点击触发回调函数
                                                 >
                                                     {city}
                                                </SubMenu>
                                            )
                                        }
                                    </SubMenu>
                                </Menu>
                            </Sider>
                            )

      getProvinceList=()=>{
        const result=fetch('/web/chargeTrend/getChargePrinceList.htm'
            ,{method:'GET',
                credentials:'include',
            }).then((res)=>{
            return res.json();
        }).then((data)=>{
            //var ds=eval('('+data+')');
            console.log('ds',data);
            if(data.length>0)
            {
                if(this.state.openKeys[0]==="全国")
                {
                    this.setState({
                        provinceList: data,
                        openKeys:[],
                    },()=>{
                        console.log('privince',this.state.provinceList);
                    })
                }else{
                    var arrs=["全国"];
                    this.setState({
                        provinceList: data,
                        openKeys:arrs,
                    },()=>{
                        console.log('privince',this.state.provinceList);
                    })
                }


            }
        });
    }
    getCity=(parentid,name)=>{
        var arr=this.state.openKeys;

        const result=fetch('/web/chargeTrend/getChargeCityList.htm?parentid='+parentid,
            {method:'GET',
                credentials:'include',
            }).then((res)=>{
            return res.json();
        }).then((data)=>{
            console.log('city',data);
            if(data.length>0)
            {
                if(parentid===this.state.openKeys[1])
                {
                    var arrs=["全国"];
                    this.setState({
                        cityList:data,
                        adCode:parentid,
                        sRange:name,
                        openKeys:arrs,
                    },()=>{
                        console.log('cityList',this.state.cityList);
                        console.log('city1',this.state.openKeys);
                    });
                }else{
                    var arrs=["全国"];
                    arrs.push(parentid);
                    this.setState({
                        cityList:data,
                        adCode:parentid,
                        sRange:name,
                        openKeys:arrs,
                    },()=>{
                        console.log('cityList',this.state.cityList);
                        console.log('city1',this.state.openKeys);
                    });
                }

            }
        });
    }
    getCountryList=(parentid,name)=>{
        var arr=this.state.openKeys;
        const result=fetch('/web/chargeTrend/getCountyList.htm?parentid='+parentid,
            {method:'GET',
                credentials:'include',
            }).then((res)=>{
            return res.json();
        }).then((data)=>{
            console.log('country',data);
            if(data.length>0)
            {
                if(this.state.openKeys.length>=3)
                {
                    if(parentid===this.state.openKeys[2])
                    {
                        var arrs=["全国"];
                        arrs.push(arr[1]);
                        this.setState({
                            countryList:data,
                            adCode:parentid,
                            sRange:name,
                            openKeys:arrs,
                        },()=>{
                            console.log('Country1',this.state.openKeys)
                        });
                    }else{
                        var arrs=["全国"];
                        arrs.push(arr[1]);
                        arrs.push(parentid);
                        this.setState({
                            countryList:data,
                            adCode:parentid,
                            sRange:name,
                            openKeys:arrs,
                        },()=>{
                            console.log('Country2',this.state.openKeys)
                        });
                    }
                }else{
                    arr.push(parentid);
                    this.setState({
                        countryList:data,
                        adCode:parentid,
                        sRange:name,
                        openKeys:arr,
                    },()=>{
                        console.log('Country3',this.state.openKeys)
                    });
                }


            }
        });
    }
}  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值