简体   繁体   中英

set array inside flatlist render in react native

Hi I want to set an array for posting . Though I have already set Array for displaying in Flatlist Now I have to post . Here is my code

 <FlatList
          data={this.state.data}
          showsVerticalScrollIndicator={false}
          renderItem={({ item }) => (
            <View
               <Text
                style={{
                  flex: 2,
                  fontSize: 15,
                  // fontFamily: "Roboto",
                  // justifyContent: "space-between",
                  width: 150
                }}
              >

                {item.rollno}
                --
                {item.name}
              <RadioForm
                animation={true}
                buttonColor={"#C2E3A9"}
                formHorizontal={true}
                labelHorizontal={true}
                buttonStyle={{ marginRight: 20 }}
                radioStyle={{ paddingRight: 20 }}
                //  labelHorizontal={false}
                style={{
                  flex: 1,
                  paddingRight: 20,
                  flexDirection: "row",
                  //padding: 10,
                  width: 30
                }}
                radio_props={radio_props}
                initial={this.state.value}
                onPress={value => {
                  this.setState({ value: value });
                }}
                ItemSeparatorComponent={this.renderSeparator}

How I want set Array because I want post .I want like this [enter link description here][1]

[1]: http://jsfiddle.net/jensbits/MWSeg/ . How I can do this .

You need to do just 2 things to add new post value in flatlist array

1 push posted data in state and re-render

this.state.data.push(newPost) // push data
this.setState({ }) // update state for re-render  

2 Update flatList

   extraData={this.state}
    //for example
   <FlatList
     data={this.state.data}
     extraData={this.state}     
     renderItem={({ item }) => (
     <View
     //Your stuff
    </View>
</FlatList>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM