以数组角度返回特定对象

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了以数组角度返回特定对象相关的知识,希望对你有一定的参考价值。

我开始使用角度。我需要返回与搜索匹配的对象,或者至少包含该对象。请指教,我目前正在归还所有物品

return items.filter( it => {
    console.log('awe', it[0].quoteOrderId.includes(searchText);
    if(it[0].quoteOrderId.includes(searchText) == true){
        console.log("we need the specific object returned");
    }
    else{
      return it;
    }
    });

}

答案
return items.filter( it => {
    if (it[0].quoteOrderId.includes(searchText) == true){
        const found = it.find(function(response){
            return response;
        })
        return found;
    }
    else {
      return '';
    }
    });
   }

这就是我想要的

以上是关于以数组角度返回特定对象的主要内容,如果未能解决你的问题,请参考以下文章