我没有在 React TypeScript 中返回号码
I'm not getting back number in react typescript
我有这样的代码:
type State = {
...
PromotionIDs: Number[];
autoAdjustUsage: AutoAdjustUsage[]
};
const InitState: State = {
...
PromotionIDs: [],
autoAdjustUsage: []
};
const contracts = this.state[PointsTableType.ELIGIBLE].contracts;
let result = this.state.PromotionIDs.map(i=>Number(i));
const autoAdjustPayload = {
promotionIDs: result,
usageYears: contracts.map(x => ({ usageYearId: x.usageId, applied: x.appliedPoints,usageType:x.usageType }))
};
console.log("this.state.PromotionIDs: ", this.state.PromotionIDs)
当我 console.log PromotionID 时,我没有返回任何号码。有谁知道我该如何解决这个问题?
要在状态中拥有该值,您必须更新状态。
像这样的东西应该有用。
...
let result = this.state.PromotionIDs.map(i=>Number(i));
this.setState({ PromotionIDs: result });
...
我有这样的代码:
type State = {
...
PromotionIDs: Number[];
autoAdjustUsage: AutoAdjustUsage[]
};
const InitState: State = {
...
PromotionIDs: [],
autoAdjustUsage: []
};
const contracts = this.state[PointsTableType.ELIGIBLE].contracts;
let result = this.state.PromotionIDs.map(i=>Number(i));
const autoAdjustPayload = {
promotionIDs: result,
usageYears: contracts.map(x => ({ usageYearId: x.usageId, applied: x.appliedPoints,usageType:x.usageType }))
};
console.log("this.state.PromotionIDs: ", this.state.PromotionIDs)
当我 console.log PromotionID 时,我没有返回任何号码。有谁知道我该如何解决这个问题?
要在状态中拥有该值,您必须更新状态。
像这样的东西应该有用。
...
let result = this.state.PromotionIDs.map(i=>Number(i));
this.setState({ PromotionIDs: result });
...