将两个对象数组与 Angular 2 和 TypeScript 合并? [英] merge two object arrays with Angular 2 and TypeScript?

查看:44
本文介绍了将两个对象数组与 Angular 2 和 TypeScript 合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经浏览过关于这个主题的 JavaScript 问题,这个问题专门关于 Angular2 和 TypeScript.

I have gone across the JavaScript questions on this topic, this question is specifically about Angular2 with TypeScript.

我想要做的是将 json 对象连接到一个数组.

What I am trying to do is to concatenate the json objects to an array.

我的代码看起来像这样,

My code looks something like this,

public results: [];


public getResults(){
    this._service.get_search_results(this._slug, this._next).subscribe(
            data => {
                this.results.concat(data.results);
                this._next = data.next;
            },
            err => {
                console.log(err);
            }
        );
}

如何使用 typescript 和 angular 将 data.results 连接到 this.results?

How can I concatenate data.results to this.results with typescript and angular?

this._slugthis._next 在类上设置.

谢谢.

推荐答案

With angular 6 spread operatorconcat 不起作用.您可以轻松解决:

With angular 6 spread operator and concat not work. You can resolve it easy:

result.push(...data);

这篇关于将两个对象数组与 Angular 2 和 TypeScript 合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆