[英]Javascript function seems to be returning true when it should be returning false
[英]why is this function returning false when it should return true?
我有一個簡單的代碼庫,少於30行,它有一個名為disable()
的函數,它驗證另一個數組內的數組內部的數組值(綁定到復選框)並返回true,如果:
null
這是功能:
disable() {
if (!this.checked_y.length) {
return true;
}
this.checked_y.forEach(year => {
year.specs.forEach(sp => {
if (sp.spec == null) {
return true;
}
});
});
return false;
}
你可以在這里找到完整的代碼
您無法從內部回調返回外部函數,但是您可以將Array#some
用於嵌套數組,如果為short則返回true。
function disable() {
return !this.checked_y.length
|| this.checked_y.some(year => year.specs.some(sp => sp.spec == null));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.