0

例如,一堆糕点店显示在下拉/选择器中。这是给定示例的以下代码:

  const [pastryShopName, setPastryShopName] = useState("")


          <Picker selectedValue={insect} style={styles.pickerStyles} onValueChange={(itemValue) => setPastryShop(itemValue)} >
            <Picker.Item label="A" value="A" onPress={(e)=>setPastryShop("A")}/>
            <Picker.Item label="B" value="B" onPress={(e)=>setPastryShop("B")}/>
            <Picker.Item label="C" value="C" onPress={(e)=>setPastryShop("C")}/>
          </Picker>
// A, B, C are the names of the pastry shop

现在,我想显示商店中所有产品的名称。为此,以下是我编写的代码:

      const pickerItems1 = ""
      if (pastryShop == "A") {
        pickerItems1 = ["Select Food", "A1", "A2", "A3"].map(i => (
          <Picker.Item label={i.toString()} value={i} key={i} />
          ))
      }
          // A1, A2, A3 are the names of the food items
          // and in the HTML part

          <Picker selectedValue={insect} style={styles.pickerStyles} onValueChange={(itemValue) => setInsect(itemValue)} >
              {pickerItems1}
          </Picker>

从上面的代码中,我希望,每当我单击 A(选择糕点店时)时,选择食物的 Picker 值也应该更改为 A1、A2、A3。

系统/项目配置:

  • Windows 10(12GB RAM、256GB SSD、1TB HDD)
  • 节点 JS (14.18.1)
  • 世博会(5.0.3)
  • 反应原生 (0.64.3)

我用于这个项目的 Picker 是 @react-native-picker/picker (2.2.1)

错误

我收到此错误:

undefined 不是对象(评估 'this.props.children[position].props)

4

0 回答 0