react 原生多选 : Cannot read the property 'getSelectedItemsExt' of undefined

标签 react-native multiple-select

我正在构建一个应用程序并引用此 link 我为我的应用程序实现了相同的代码,但我收到错误“无法读取未定义的属性'getSelectedItemsExt'”。 另一个错误是“提交”按钮也没有出现。我已经尝试了所有方法,但都失败了。

import React, { Component } from 'react';
import { AppRegistry, StyleSheet, TextInput, View, ListView, Alert, Button,     Platform, ToastAndroid, TouchableOpacity, ActivityIndicator, Text, Picker, ScrollView }
from 'react-native';
import { StackNavigator } from 'react-navigation';
import MultiSelect from 'react-native-multiple-select';


class manage_publishers extends Component {
static navigationOptions = {
    title: 'Manage Publishers',
};

constructor() {
    super()
    this.state = {
        isLoading: true,
        selectedPublishers1:[],
        publishersByCategory: [],
        publishersByClient: [],
        publishersByGroup: [],
        dataSource:[]
    }
}

componentDidMount() 
{
    const base64 = require('base-64');
    fetch('APIURL'+this.props.navigation.state.params.id, 
    {
        method: 'GET',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
            "Authorization": "Basic " + base64.encode("ABC:XYZ")
        }
    }).then((response) => response.json()
    )
        .then((responseJson) => {
            this.setState({
                categories: responseJson.PublisherByCategory,
            }, function () {

        });
    })
    .catch((error) => {
        console.log("error in category");
        console.log(error);
    });


}

onSelectedPublishersByCategoryChange = (publishersByCategory) => {
    console.log(publishersByCategory);
    this.setState({ publishersByCategory });
}



render() {
    const { navigate } = this.props.navigation;
    if (this.state.isLoading) {
    return (
    <View style={{ flex: 1, paddingTop: 20 }}>
      <ActivityIndicator />
    </View>
  );
}
return ([
  <View style={{flex: 1,paddingTop: (Platform.OS === 'ios') ? 20 : 20, padding: 5}}>
    <Text style={{ padding: 5, fontSize: 35, backgroundColor: '#2196F3', marginBottom: 7 }}>
        Manage Publishers
    </Text>
    <MultiSelect
      items={this.state.categories}
      uniqueKey="id"
      ref={(component) => { this.multiSelect = component }}
      onSelectedItemsChange={this.onSelectedPublishersByCategoryChange}
      selectedItems={this.state.publishersByCategory}
      selectText="Publishers by Category"
      searchInputPlaceholderText="Search Publisher..."
      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"
    />
  </View>,
  <View>
     {this.multiSelect.getSelectedItemsExt(selectedItems)} 
  </View>
 ]);
}
}
});

 module.exports = manage_publishers;

请看看这个并为我提供解决方案,我将非常感激。

最佳答案

我遇到了同样的问题,我解决了添加 AND 条件:

{this.multiSelect && this.multiSelect.getSelectedItemsExt(selectedItems)}

关于 react 原生多选 : Cannot read the property 'getSelectedItemsExt' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49442714/

相关文章:

react-native - react 导航以从 redux 操作文件中导航

react-native - 导出 const 变得未定义

android - React-Native:当应用程序离线(无互联网访问)时,无法使用 firestore 添加或设置()文档

php - 从数据库语法错误中使用(select=true)表单填充多个选择

PHP ( Wordpress) - 选择多个 - 显示 "selected"状态不工作

javascript - 根据其他多选中的选择填充多选

android - 在使用 Android 模拟器启动应用程序时 react native 错误

vb6 - 在 vb6 的列表框中限制选择

select - 选择(通过收获): is it possible to allow element which are not in the list in a multiple select list?

react-native - 为多个应用程序使用单个 expo 代码库