arrays - 如何在外部方法之外获取返回值
问题描述
我是 Angular 的新手,我对获取它的返回值的问题感到困惑。我已经在另一个内部实现了一个功能。
private validateKeyterm(): boolean {
const val = this.form.value.term;
if (this.selectedTermType == 'keywords') {
// filter out data
this.keywordTemp.filter(function (d) {
if((d.term.toString().indexOf(val) !== -1 || !val) == true){
console.log("keytemp: true");
return true;
}
}) ;
} else {
this.profanityTemp.filter(function (d) {
if((d.term.toString().indexOf(val) !== -1 || !val) == true){
console.log("profanity: true");
console.log("true");
return true;
}
else{ return null;}
});
}
console.log("false");
return false;
}
但是在此函数执行中,我总是将返回值设为“失败”。谁能找到我的解决方案,从“validateKeyterm”函数中获取“真实”案例。
解决方案
我必须检查您在此函数中使用的值,但根据您的代码,我建议您在过滤器函数中使用箭头函数,如下所示:
private validateKeyterm(): boolean {
const val = this.form.value.term;
if (this.selectedTermType == 'keywords') {
// filter out data
return !!(this.keywordTemp.filter(d => {
if((d.term.toString().indexOf(val) !== -1 || !val) == true){
console.log("keytemp: true");
return true;
}
}));
} else {
return (this.profanityTemp.filter( d => {
if((d.term.toString().indexOf(val) !== -1 || !val) == true){
console.log("profanity: true");
console.log("true");
return true;
}
else{ return null;}
}));
}
console.log("false");
return false;
}
推荐阅读
- python - .lower 函数在 lambda 中如何工作?
- java - 如何在 Android 中添加对实时推送通知的支持?
- c - 使用 openmp 并行化矩阵乘法并使用 avx2 进行矢量化
- python - 模拟 Python 测试的长网络请求
- regex - Perl 在双连字符或字母数字处拆分
- r - 如何根据键列表替换字符串中的多个值
- c# - 为什么任务
.Result 如果 Task 抛出异常 .IsCompleted 是真的吗? - android - 如何从存储中获取图像的真实路径 - Android API 29?
- php - author_id(table event) != auth()->user(); 时如何禁用按钮;但超级管理员可以访问该按钮
- pandas - 如何计算部分更新信息的均值、中位数和标准差?