【问题标题】:Want to show the data in a dropdown every item as an option想要在下拉列表中显示每个项目的数据作为选项
【发布时间】:2020-02-16 06:01:16
【问题描述】:
class DropDown extends Component {
    constructor(){
        super()
        this.state = {
            item: [],
            isLoaded: true,
        }
    }
// here I have fetch the data from api
    componentDidMount() {
        fetch('link')
            .then((response) => response.json())
            .then((responseJson) => {
                this.setState({
                    isLoaded: false,
                    item: responseJson.drawingInfo.renderer.uniqueValueInfos,

                })


            })

    }

    render() {
        const {item} = this.state;

// here I have map the array of data. And now wanna show it in a dropdown where every item is an option an we can select them


        const itemDropdown = item.map((division, index)=> (
            <div key={index}>

                    <option>{division.value}</option>

            </div>

        ))

        return (
{/*here I tried to show the data as dropdown option...but I got one option where all the data resides*/}
            <div>
                <ReactBootStrap.DropdownButton variant = 'transparent' id = "dropdown-button" title="Dropdown button" >
                    < ReactBootStrap.Dropdown.Item > {itemDropdown} </ReactBootStrap.Dropdown.Item> 

                </ReactBootStrap.DropdownButton>

            </div>
        );

    }
}

【问题讨论】:

    标签: reactjs dropdown react-dropdown-tree-select


    【解决方案1】:

    react bootstrap dropdown 让使用 react 和 bootstrap 变得更容易:

    render (){
     const {item} = this.state;
      return (
        <DropdownButton title="Dropdown">
        { item.map((division, index)=> (
              <MenuItem>{division}</MenuItem>
        )
        </DropdownButton>
      );
    }
    

    【讨论】:

      猜你喜欢
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 2012-11-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多