Javascript 在数组值更新后反应本机选择器显示

Javascript 在数组值更新后反应本机选择器显示,javascript,react-native,Javascript,React Native,我是新手,我有一个问题。首先,我将解释我的工作。我有一个数组对象最初有一些值。componentWillMount函数将以json格式从我的数据库中获取值。我解析json以存储在我的对象数组中。之后,我希望在我的选择器列表标签中看到该值 问题是只有初始值显示在我的选择器列表中。我需要在数据库解析值中存储的数组对象之后显示一个值 这是我的密码 constructor(props){ super(props); this.state = { a: [{"id": 0, "wi

我是新手,我有一个问题。首先,我将解释我的工作。我有一个数组对象最初有一些值。componentWillMount函数将以json格式从我的数据库中获取值。我解析json以存储在我的对象数组中。之后,我希望在我的选择器列表标签中看到该值

问题是只有初始值显示在我的选择器列表中。我需要在数据库解析值中存储的数组对象之后显示一个值

这是我的密码

constructor(props){
  super(props);
  this.state = {
        a: [{"id": 0, "windID": "1", "windname": "a"},],
        windFormID:'',
  }
}
componentWillMount(){
   return  fetch('http://api.kiot.katomaran.com/api/v1/wind_farms', {
   method: 'GET',
   headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  },
  })

.then((response) => response.json())
.then((responseJson) => {
  if (responseJson.status === true){
  for ( i = 0,len = responseJson.data.length ; i < len; i++) { 
    if(i===0)
    {
        this.state.a[0]={'id':i,'windID' : responseJson.data[i].id,'windname' : responseJson.data[i].name}
    }
    else{
    this.state.a.push({'id':i,'windID' : responseJson.data[i].id,'windname' : responseJson.data[i].name}) 
    }
  }
  console.log(this.state.a)

  }
  else{
    alert(responseJson.message); 
  }
})
构造函数(道具){
超级(道具);
此.state={
a:[{“id”:0,“windID”:“1”,“windname”:“a”},],
风蚁:'',
}
}
组件willmount(){
返回获取('http://api.kiot.katomaran.com/api/v1/wind_farms', {
方法:“GET”,
标题:{
“接受”:“应用程序/json”,
“内容类型”:“应用程序/json”,
},
})
.then((response)=>response.json())
.然后((responseJson)=>{
if(responseJson.status==true){
对于(i=0,len=responseJson.data.length;i
}


this.setState({windFormID:itemValue})}>
{this.state.a.map((键,索引)=>{
返回()
})}
昨天有人帮我解决了这个问题。但这不能解决任何问题。
我被困在这里两天了……

使用
setState

让newarray=[];
对于(i=0,len=responseJson.data.length;i
Bro我想映射特定项的值:{windID}用于特定标签:{windname}@JAYARAM发布thatK Bro的不同问题最后非常感谢
    <Picker 
            selectedValue={this.state.windFormID}
            style={styles.button} 
            onValueChange={(itemValue, itemIndex) => 
            this.setState({windFormID: itemValue})}>
            {this.state.a.map((key, index) => {
            return(<Picker.Item label={key.windname} value={index} key= 
            {index}/>)
            })}
    </Picker>
    let newarray=[];
    for ( i = 0,len = responseJson.data.length ; i < len; i++) { 
        newarray.push({'id':i,'windID' : responseJson.data[i].id,'windname' : responseJson.data[i].name}) 
      }
     this.setState({a:newarray})