React Native Picker获取数组

时间:2018-01-26 22:14:50

标签: arrays reactjs api react-native

我正在使用React Native Picker(官方)。 在我的选择器组件中,我不仅需要特定选择记录的id,还需要所有数据,如名称,地址等......

 <Picker
    mode="dropdown"
    headerStyle={{ backgroundColor: "#16334c" }}
    headerBackButtonTextStyle={{ color: "#fff" ,marginLeft:-20}}
    headerTitleStyle={{ color:'#fff',alignSelf:'center',marginLeft:50,width:'100%'}}
    textStyle={{color:'#fff',fontSize:12,paddingLeft:8}} 
    style={{height:35,color:'#fff',width:'110%'}}
    selectedValue={this.state.value}
    onValueChange={(itemvalue) =>  this.GetPickerSelectedItemValue(itemvalue)}
    >

        this.props.dropDownType.map((item,i) => {
        return <Item label={item.name} value={item.id} key={i} />
    })}

    </Picker>

这是我的函数GetPickerSelectedItemValue

GetPickerSelectedItemValue(itemvalue){
 this.setState({value:itemvalue});
}

问题是它只给了我选择项的特定id。我需要项目的数组..

如果我更改代码

<Item label={item.name} value={item} key={i} />

然后它给我数组然后在我的函数上我可以访问所有变量,如item.iditem.nameitem.phone

但主要的问题是我有两个屏幕,第一个是'添加部分',第二个是'编辑部分'在两个屏幕上有两个下拉菜单(拣货员)。在addpart屏幕上它工作正常但在editpart上有一个问题,当用户点击编辑我发送的下拉值时,它已经选择了如

  <DropDown
  value={this.state.equipmentLocationID}
  dropDownType={this.state.dataSource.equipment_location}
  left={'88%'}/>

我传递了一个值道具,然后将状态值设置为此类道具,如值this.props.value并在选择器的selectedValue道具中调用此状态,但它仅在我添加{{{ 1}},它不起作用value={item.id}表示默认情况下它不会在编辑屏幕上显示选择器上的选定值。

我需要整个特定id的数组,因为我需要在api上发送该id的其他字段,这就是为什么我这样做...

请帮忙???

0 个答案:

没有答案