类型错误:无法读取未定义的 RNPickerSelect

时间:2021-01-29 04:53:35

标签: javascript react-native select

我想在我的应用程序中进行两个选择器选择,但我有代码错误

这是两个生成我的数据以在选择中显示

const generateSubject = () => {
    const theSubject = dataSubjects?.subjectsConnection?.data?.map((item) => {
      return (
        item && {
          key: item.id,
          value: item.id,
          label: item.name,
        }
      )
    })
    return theSubject
  }

  const generateBasicCompetence = () => {
    const theBasicCompetence = dataBasicCompetences?.basicCompetencesConnection?.data?.map(
      (item) => {
        return (
          item && {
            key: item.id,
            value: item.id,
            label: item.code,
          }
        )
      },
    )
    return theBasicCompetence
  }

这是我的 rnpickerselect,但我有这样的错误 TypeError:无法读取未定义的属性“标签”

                      <RNPickerSelect
                            key={index}
                            placeholder={{
                              label: translations["choose.subject"],
                              color: theme.colors.placeholder,
                            }}
                            onValueChange={(value) => {
                              setSubjectAssignment((prev) => {
                                prev[index].subjectId = value
                                return [...prev]
                              })
                            }}
                            items={generateSubject()}
                            style={{
                              inputAndroid: {
                                color: theme.colors.text,
                              },
                            }}
                          />
                         <RNPickerSelect
                            key={index + 1}
                            placeholder={{
                              label: translations["select.basic.competences"],
                              color: theme.colors.placeholder,
                            }}
                            onValueChange={(value) => {
                              setSubjectAssignment((prev) => {
                                prev[index].basicCompetenceId = value
                                return [...prev]
                              })
                            }}
                            items={generateBasicCompetence()}
                            style={{
                              inputAndroid: {
                                color: theme.colors.text,
                              },
                            }}
                          />

谁能帮帮我?因为如果只有一个选择器选择,它不会出错

0 个答案:

没有答案