我是新来的本地人。我正在构建一个应用程序,其中有一个详细信息屏幕,其中有一个带有文本的按钮(CUT),并且后端的状态为0 。当用户单击按钮时,将调用发布请求,并且后端的状态设置为1 ,并且按钮文本将转换为(已处理)。但是现在的问题是,当用户单击 button(CUT)时,它会发布在api上,但不是实时更新,而是再次获取所有数据并再次渲染整个屏幕,然后将其转换为< strong>(已处理)。我不想再次渲染整个屏幕,我只想渲染该按钮。
Redux操作文件
export const CutDone = id => dispatch => {
dispatch(setCuttingLoading());
axios
.post(
`http://192.168.0.1:3000/api/MobileApp/ProcessCutPiece?planDetailId=${id}`
)
.then(res => {
if (res.data.indexOf("Ok") > -1) {
Alert.alert(
"Success",
`Cutting done of id ${id}`,
[
{
text: "OK"
}
],
{ cancelable: false }
);
} else {
Alert.alert(
"Error!",
`${res.data}`,
[
{
text: "OK"
}
],
{ cancelable: false }
);
}
})
.catch(err => {
dispatch({
type: GET_ERRORS,
payload: null
});
console.log(err);
});
};
详细信息屏幕
onProcessedCutPiece(PlanDetailId) {
this.props.CutDone(PlanDetailId);
}
<View style={{ alignItems: "center", flex: 1 }}>
{newItem.Status === 0 ? (
<Button
bordered
small
primary
onPress={this.onProcessedCutPiece.bind(
this,
newItem.PlanDetailId
)}
>
<Text>Cut</Text>
</Button>
) : (
<View style={{ alignItems: "center", flex: 1 }}>
<Text style={styles.processedText}>
<Icon
type="Feather"
style={styles.processIcon}
name="check-circle"
/>{" "}
Processed
</Text>
</View>
)}
</View>
OnPress,我只想再次渲染该按钮,而不是整个屏幕
答案 0 :(得分:0)
请尝试从dispatch(setCuttingLoading())
操作中删除CutDone
,并在onPress
方法中尝试设置newItem.status=1