我有一个展示名称和状态的Flatlist, 我想通过单击平面列表项来切换用户的状态。 我已经为此创建了redux动作和redux减速器。但是无法改变相应的状态。
{
"response": [{
"name": "RAJ",
"status": true
}, {
"name": "RAM",
"status": true,
}]
}
<FlatList
showsVerticalScrollIndicator={false}
removeClippedSubviews={false}
data={this.props.response}
ItemSeparatorComponent = {this.flatListItemSeparator}
ListFooterComponent={this.flatListItemSeparator}
keyExtractor={(item, index) => index}
renderItem={({item,index}) => this.renderFlatListItem(item,index)}/>
但无法更改与指定用户对应的状态。例如Raj状态为false
{{1}}
答案 0 :(得分:1)
我不知道这是否正是你想要实现的目标,但我会试一试。
//call Action
this.props.listItemClick('RAJ',false});
//Action
export const listItemClick = (user,status) => {
return {
type: LIST_CLICK,
payload: { user, status }
};
};
export default (state = INITIAL_STATE, action) => {
switch (action.type) {
case LIST_CLICK:
//replace YOUR_DATA with your state var
return {...state, YOUR_DATA: [state.YOUR_DATA.map((val,index) => {
if (val.name === action.payload.user) {
return { ...val, status: action.payload.status };
}
return { ...val };
})]};
default:
return state;
}
};