React native 当状态中的数据更改时,组件不呈现
我有一个包含特定数据的列表视图。当发生另一个操作时,我需要更新列表视图中一个项目的样式。我正在状态中存储更改。但是组件没有被渲染React native 当状态中的数据更改时,组件不呈现,react-native,React Native,我有一个包含特定数据的列表视图。当发生另一个操作时,我需要更新列表视图中一个项目的样式。我正在状态中存储更改。但是组件没有被渲染 export default class App extends Component { constructor(props) { super(props); this.state = { loading: false, data: [], sectionlistData: Data["SearchList"], headers
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
loading: false,
data: [],
sectionlistData: Data["SearchList"],
headers: this.GetHeaders(Data["SearchList"]),
current: 'A'
};
}
someAction(){
this.setState({
current: info.viewableItems[0].section.title+""
})
}
render() {
return (
<View style={{ marginTop : (Platform.OS) == 'ios' ? 20 : 25 }}>
// some code
<View style={styles.contentListView}>
<FlatList
style={styles.alphabeticView}
data={this.state.headers}
renderItem={({item}) => <Text style={this.state.current===item.key ?
styles.alphabetsHighlight : styles.alphabets} onPress=
{this.GetListItem.bind(this, item)} >{item.key}</Text>}
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
alphabets:{
textAlign: 'right',
paddingRight: 10,
height: 15,
color: '#005B9A',
backgroundColor: 'transparent',
},
alphabetsHighlight:{
textAlign: 'right',
paddingRight: 10,
height: 15,
fontWeight: 'bold',
color: '#005B9A',
backgroundColor: 'transparent',
}
});
导出默认类应用程序扩展组件{
建造师(道具){
超级(道具);
此.state={
加载:false,
数据:[],
sectionlistData:Data[“SearchList”],
headers:this.GetHeaders(数据[“搜索列表]),
当前:“A”
};
}
someAction(){
这是我的国家({
当前:信息。可查看项[0]。节。标题+“”
})
}
render(){
返回(
//一些代码
{item.key}
/>
);
}
}
const styles=StyleSheet.create({
字母表:{
textAlign:'右',
paddingRight:10,
身高:15,
颜色:“#005B9A”,
背景色:“透明”,
},
字母表突出显示:{
textAlign:'右',
paddingRight:10,
身高:15,
fontWeight:'粗体',
颜色:“#005B9A”,
背景色:“透明”,
}
});
在代码中,我使用状态切换样式,但当我更新状态时,它不会重新渲染。我的做法正确吗?在CSS类中使用状态数据时,react是否呈现组件?我如何使用下面的方法实现目标。如果这对我没有帮助,我如何才能实现我想要的。平面列表是一个纯组件。它将根据传递给
extraData
的内容重新渲染。因此,尽管您的状态正在改变,但平面列表的extraData
应该会改变!我想,你可以直接转到extraData
,this.state
,一切都会很好地更新。哦,谢谢,我已经看了文档,但是我忘记了关于FlatList的事情。