Forum Discussion

Americo Perez's avatar
Americo Perez
Iron Contributor
Apr 11, 2019
Solved

Pass state to Dropdown options?

Hi I am trying to populate the options parameter of the Dropdown component from a state but nothing shows in Dropdown because the state is empty when the Dropdown get rendered.    this is how I am...
  • Beau Cameron's avatar
    Beau Cameron
    Apr 12, 2019

    Americo Perez I suggest doing some React training online before trying to build solutions in your SharePoint environment. You want to make sure you are putting in well built solutions.

    So get your IView[] result back, loop through them and create a new IDropDown[] for each view. Set your state to your IDropDown[].


    private _options = IDropdownOption[] = [];

     

    this.props.provider.getViews().then((views: IView[]) => {
                  views.map(view => {
                        this._options.push({
                               key:view.Id,
                               text:view.Title
                            });
                    });
                   this.setState({views:this._options})
           });




Resources