【发布时间】:2019-10-25 02:10:53
【问题描述】:
t.budget.budgetGroup.name 这里有上述错误。我无法重新创建此错误。但是 Sentry 将其显示为运行时异常。这可能吗?因为我已经初始化了new Budget() 和new BudgetGroup()。那么我该如何解决呢?
data: DtoBudgetGroup;
constructor(){}
init() {
this.data = this.navParams.get('data');
}
let filteredTransactions: Transaction[] = filter(this.data.transactions, (t:
Transaction) => { return t.budget.budgetGroup.name == this.data.budget.budgetGroup.name; });
export class Transaction {
id: string;
budget: Budget = new Budget();
}
export class Budget {
id: string;
budgetGroup: BudgetGroup = new BudgetGroup();
}
export class BudgetGroup {
id: string;
name: string;
}
export class DtoBudgetGroup {
budget: Budget;
budgetGroup: BudgetGroup;
budgetTotal: number;
transactionTotal: number;
transactions: Transaction[];
isTransactionOver: boolean = false;
}
this.data = this.navParams.get('data');
【问题讨论】:
-
这取决于 this.data.transactions 是如何初始化的。如果它是 Web API 的响应,那么您的类将不会自行实例化。获得 JSON 数据后,您需要通过将 JSON 数据映射到所需的类集合来实例化。
-
@user2216584 我添加了更多数据。请看。没有 API。这是
Firestore数据。 -
是的,你称之为@user2216584 - 一个异步问题 - 不是打字稿问题。
-
@RandyCasburn 你错了。这里的数据是预先的。这里没有异步问题。请清楚阅读问题。
this.data = this.navParams.get('data') -
@Sampath 你能在 this.data = this.navParams.get('data'); 之后分享 console.log(this.data) 的输出吗?
标签: javascript angular typescript ionic3