为什么concat为合并2个对象数组而抛出错误

时间:2017-10-27 05:43:28

标签: angular typescript ionic3

嗨'我正在Error

  

concat不是函数

我正在尝试的是

    searchResults:any;   // inside class export
    results:any


 this.candidateSearch.postSearch(this.searchedInput,"candidateSearch").then((result)=>{

     this.results = result;

     console.log(this.results.details);       

    this.searchResults = this.searchResults.concat(this.results);   // throwing error      


          }, (err) => { 

        });

我的结果是以这种格式出现的:

{
    "details": [{
        "company_name": "Cybrain Software Solutions",
        "skills": "php,laravel",
        "package": "15 lakh",
        "location": "Bengaluru",
        "industry": "Software",
        "job_type": "permanent"
    }, {
        "company_name": "Floret Media Pvt Ltd",
        "skills": "php",
        "package": "10 lakh",
        "location": "Bengaluru",
        "industry": "software",
        "job_type": "per"
    }]
}

我的问题:我想完成以前的结果

编辑:我希望searchResults数组采用此格式{"details":[{},{},{}]} after concatenation

2 个答案:

答案 0 :(得分:2)

您需要初始化数组

searchResults:any = [];  

答案 1 :(得分:0)

您现在尝试连接的是对象。所以我们需要做的是实际连接内部 对象的数组:

searchResults = {details:[]};

...

this.searchResults.details = 
    this.searchResults.details.concat(this.results.details);