javascript - 如何在 TypeScript 中打破 ForEach 循环
问题描述
我有下面的代码,在某些情况下我无法打破循环。
isVoteTally(): boolean {
let count = false;
this.tab.committee.ratings.forEach(element => {
const _fo = this.isEmptyOrNull(element.ratings.finalOutcome.finaloutlook);
const _foreign = this.isEmptyOrNull(element.ratings.finalOutcome.foreign);
const _local = this.isEmptyOrNull(element.ratings.finalOutcome.local);
const _tally = element.ratings.finalOutcome.voteTally.maj + element.ratings.finalOutcome.voteTally.dis;
if (_fo == false && _foreign == false && _local == false) {
if (_tally > 0) {
**return count = false;**
}
} else {
if (_tally < 0) {
**return count = false;**
}
}
});
return count;
}
在星标区域,我想破解代码并返回布尔值,但我现在无法做到。有谁能够帮助我。
提前致谢。
解决方案
this.tab.committee.ratings.forEach 不是运营商。打字稿允许更多可读的代码。
在样式中使用for循环,如下所示:
for(let a of this.tab.committee.ratings) {
if(something_wrong) break;
}
ps 忘记 Angular 中的“使用 jQuery 编码”。它只是行不通。
推荐阅读
- mysql - 如何从 MySQL 中的每个组中选择前两个日期?
- asp.net-core - asp.net core '没有路由与提供的值匹配' 与控制器级路由值
- angular - 包 '@angular/cli' 不是依赖项
- javascript - 确保仅当第一个 OR 元素不存在时,正则表达式才会移动到第二个 OR 元素
- r - 两个闪亮仪表板选项卡中带有 actionButton 的 renderDataTable
- python - AttributeError:“str”对象没有属性“product”
- javascript - 为什么数据中的属性不会在 setInterval 中更新
- python - 测量 Pandas 系列列中 NaN 间隙的持续时间
- javascript - 如何解决 TypeError: jquery__WEBPACK_IMPORTED_MODULE_1___default(...)(...).faceDetection is not a function
- ruby - SquareConnect::CustomersApi.search_customers 方法的使用