我有职位和预算界面,当我从对话框中添加新职位和预算时,所有职位界面都会添加,但当我重新加载页面时预算显示为 0,预算工作一切正常。我添加了一个职位,该职位已添加并显示,但是当我重新加载页面时,计划预算为 0,然后一切正常,这怎么会发生,您建议我做什么,自动显示预算,而不是何时页面重新加载。
这里有代码,这是显示位置的方法
getPosition() {
return this.positions.sort((function (a, b) {
if (a.name > b.name) {
return 1;
}})).filter(position => this.subproject.positionIds.includes(position.id)).toArray();
}
这是模板
<tr *ngFor="let position of getPosition()">
<td>{{position.name}}</td>
<td>{{costTypes[position.costType]}}</td>
<td>{{getActualBudget(position).planned | number}}</td>
<td>{{currencies[position.currency]}}</td>
<td>{{states[position.state]}}</td>
这是Position的界面
export interface Position {
id: string;
subProjectId: string;
name: string;
currency: string;
state: string;
costType: string;
budgetIds: string[];
}
这是预算的界面
export interface Budget {
id: string;
positionId: string;
created: Date;
planned: number;
blocked: number;
used: number;
free: number;
transferred: number;
transferredToId: string;
commentUsed: string;
commentFree: string;
}
这是实际预算
getActualBudget(position: Position): Budget {
return this.budgets.get(position.budgetIds[0], emptyBudget());
}
这是对话框的模板。
<app-input-field orientation="top" labelWidth="85px;" label="Planned
Budget *">
<input type="number" min="1" [(ngModel)]="newBudget.planned"
required style="width: 100%;">
</app-input-field>
这是预算的实用程序
export function emptyBudget(): Budget {
return {
id: '',
positionId: '',
created: new Date(0),
planned: 0,
blocked: 0,
used: 0,
free: 0,
transferred: 0,
transferredToId: '',
commentUsed: '',
commentFree: ''
};
}
这是效果。
upsertBudgetEffect$ = this.actions$.ofType(UpsertBudgetAction.Type).pipe(
withLatestFrom(this.store),
mergeMap(([action, state]: [UpsertBudgetAction, ApplicationState]) => {
const url = environment.backend + '/api/planning/budgets';
return this.httpClient.put<Budget>(url, action.payload).pipe(
mergeMap(response => {
const actions: Action[] = [new UpsertBudgetInternalAction(response)];
const position = state.budcon.positions.get(response.positionId);
if (position.budgetIds.includes(response.id)) {
position.budgetIds.push(response.id);
actions.push(new UpsertPositionInternalAction(position));
}
return actions;
}),
catchError(noOpHandler)
);
})
);
在条件下的效果 如果您失败了。更改自if (position.budgetIds.includes(response.id))
至
if (!position.budgetIds.includes(response.id))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句