反应本机多个选择项

时间:2019-10-01 20:23:19

标签: arrays react-native select drop-down-menu state

我有一个下拉菜单,可以选择多个项目,然后使用这些值更改正在从服务器加载一些数据的数组的状态,因此,在根据我的选择更改了这些数据之后,我的单位列表将仅显示相应的列表,而不是像我做出选择之前那样显示全部。 问题是,在删除选择之后,未像以前一样用所有数据填充平面列表。这是我正在执行所有操作的功能:

onSelectedItemsChange = selectedItems => {

    this.setState({ selectedItems });
    var newDataArray = [];
    for (i = 0; i < selectedItems.length; i++) {

        for (j = 0; j < this.state.All.length; j++) {

            if (selectedItems[i] === this.state.All[j].type) {
                const newData = this.state.All[j];
                newDataArray.push(newData);
                this.setState({
                    All: newDataArray    //"All" is an array where I load all  data and here I am populating it with new data based on the user selection
                });

                console.log(newDataArray);
            }
        }
    }
};

编辑

 <MultiSelect
                        hideTags
                        items={this.filter_pref}
                        uniqueKey="name"
                        ref={(component) => { this.multiSelect = component }}
                        onSelectedItemsChange={this.onSelectedItemsChange}
                        selectedItems={selectedItems}
                        selectText="Pick Items"
                        searchInputPlaceholderText="Search Items..."
                        onChangeInput={(text) => console.log(text)}
                        altFontFamily="ProximaNova-Light"
                        tagRemoveIconColor="#CCC"
                        tagBorderColor="#CCC"
                        tagTextColor="#CCC"
                        selectedItemTextColor="#CCC"
                        selectedItemIconColor="#CCC"
                        itemTextColor="#000"
                        displayKey="name"
                        searchInputStyle={{ color: '#CCC' }}
                        submitButtonColor="#CCC"
                        submitButtonText="Submit"
                    />

0 个答案:

没有答案