gpt4 book ai didi

json - 如何在 Angular 中连接两个对象?

转载 作者:行者123 更新时间:2023-12-04 19:50:40 24 4
gpt4 key购买 nike

如何加入 Angular 2 中的对象?

对象响应 1

0:Object
1:Object
2:Object
3:Object

对象响应 2
0:Object
1:Object
2:Object
3:Object

myComponent 组件
resultdata :any=Array;

fooddrinks_data_func(Defaultparams){

return this.CitiesService.getresult(Defaultparams).subscribe(data => {
this.resultdata = this.resultdata.join(data.categorylistvalues);

});
}

我收到这个错误。

error_handler.js:59 ORIGINAL STACKTRACE: ErrorHandler.handleError @ error_handler.js:59 next @ application_ref.js:348 schedulerFn @ async.js:93 SafeSubscriber.__tryOrUnsub @ Subscriber.js:234 SafeSubscriber.next @ Subscriber.js:183 Subscriber._next @ Subscriber.js:125 Subscriber.next @ Subscriber.js:89 Subject.next @ Subject.js:55 EventEmitter.emit @ async.js:79 NgZone.triggerError @ ng_zone.js:333 onHandleError @ ng_zone.js:294 webpackJsonp.1416.ZoneDelegate.handleError @ zone.js:338 webpackJsonp.1416.Zone.runTask @ zone.js:169 ZoneTask.invoke @ zone.js:420 error_handler.js:60 TypeError: _this.resultdata.join is not a function



最后的结果应该是这样的。

this.resultdata
0:Object
1:Object
2:Object
3:Object
4:Object
5:Object
6:Object
7:Object

最佳答案

我认为您正在寻找 object.assign() ?

The Object.assign() method is used to copy the values of all enumerable own properties from one or more source objects to a target object. It will return the target object.



var obj1 = { a: 1 };
var obj2 = { b: 2 };

var merged = Object.assign(obj1, obj2);

console.log(merged); // { a: 1, b: 2 }

关于json - 如何在 Angular 中连接两个对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43678643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com