如何将这些对象转换为打字稿中的数组
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何将这些对象转换为打字稿中的数组相关的知识,希望对你有一定的参考价值。
如何将字符串转换为Typescript数组?请帮助我。
查看代码:
private validateEmptyOption(): any {
console.log("CHECKED")
let isValid = true;
this.currentForm.sections.forEach((section: Section) => {
section.fields.forEach((field: Field) => {
debugger
if (field.type === 'select') {
console.log(field)
const emptyOptionSections = JSON.parse(field.property).emptyOptionSections;
if ((emptyOptionSections !== undefined) && (emptyOptionSections == null)) {
alert('QAZWSX');
isValid = false;
}
}
return isValid;
});
});
}
这是我在控制台中的结果。我想将其转换为数组并循环播放。
预期结果:应该有一条确认消息,告知选择控制器不能为空
实际结果:表单可以保存而无需任何验证
答案
因为您的return
语句写在错误的位置。检查您的{
}
(
)
以上是关于如何将这些对象转换为打字稿中的数组的主要内容,如果未能解决你的问题,请参考以下文章
如何将firebase REST API响应转换为打字稿中的数组?