1

我是新来的反应本地人。我正在构建一个应用程序,其中有一个详细信息屏幕,其中有一个带有文本( CUT )的按钮,并且后端中的状态为 0 。当用户单击按钮时,将调用发布请求,并且在后端将状态设置为 1 ,并且按钮文本将转换为 (Processed)。但是现在的问题是,当用户单击按钮(CUT)时,它会在 api 上发布,但不会实时更新它,它会再次获取所有数据并再次渲染整个屏幕,然后将其转换为(processed)。我不想再次渲染整个屏幕我只想渲染那个按钮。

图片

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 我只想再次渲染该按钮而不是整个屏幕

4

1 回答 1

0

请尝试dispatch(setCuttingLoading())CutDone操作中删除并在onPress方法中尝试设置newItem.status=1

于 2019-09-02T09:35:34.983 回答