react-native-sectioned-multi-select onSelectedItemsChange不被调用

时间:2019-04-30 18:49:55

标签: javascript reactjs react-native npm expo

我正在尝试在expo react-native应用程序中实现多选,但从未调用过onSelectedItemsChange的回调。这是我的组件的外观。


import React, {Component} from 'react'
import { View, Picker } from 'react-native';
import SectionedMultiSelect from 'react-native-sectioned-multi-select';

const items = [
      {
          "resource_uri": "https://www.eventbriteapi.com/v3/categories/103/",
          "id": "103",
          "name": "Music",
          "name_localized": "Music",
          "short_name": "Music",
          "short_name_localized": "Music"
      },
      {
          "resource_uri": "https://www.eventbriteapi.com/v3/categories/101/",
          "id": "101",
          "name": "Business & Professional",
          "name_localized": "Business & Professional",
          "short_name": "Business",
          "short_name_localized": "Business"
      },
      {
          "resource_uri": "https://www.eventbriteapi.com/v3/categories/110/",
          "id": "110",
          "name": "Food & Drink",
          "name_localized": "Food & Drink",
          "short_name": "Food & Drink",
          "short_name_localized": "Food & Drink"
      },
      {
          "resource_uri": "https://www.eventbriteapi.com/v3/categories/113/",
          "id": "113",
          "name": "Community & Culture",
          "name_localized": "Community & Culture",
          "short_name": "Community",
          "short_name_localized": "Community"
      },
]

onSelectedItemsChange = (selectedCatagories) => {
  debugger
  this.setState({ selectedCatagories });
}

export default class MultiSelectComponent extends Component {
  constructor(){
    super()
    this.state = {
      selectedCatagories: []
    }
  }

  render() {
   const { selectedCatagories } = this.state;
   return (
     <View>

        <SectionedMultiSelect
          items={items}
          uniqueKey='id'
          selectText='Choose some categories...'
          showDropDowns={true}
          readOnlyHeadings={true}
          onSelectedItemsChange={selectedItems => console.log(selectedItems)}
          selectedItems={selectedCatagories}
        />

      </View>
   );
 }
}

一切都正确显示,但console.log函数从未被调用,如果我连接该函数,则项目旁边不会显示复选标记。

0 个答案:

没有答案