Javascript 组合从json文件中剔除的多个对象,并作为可观察对象返回
我想将对象Javascript 组合从json文件中剔除的多个对象,并作为可观察对象返回,javascript,angular,typescript,Javascript,Angular,Typescript,我想将对象this.webCustomAlert,this.webCustomAuth,this.webcustomecomerce组合成一个对象。它们都具有共同的性质。因此,我想从以下几点开始: webCustomAuth [{ "type":"google-login", "cost":30, "buildTime":2 },{ "type":"twitter-login", "cost":30, "buildTime":2 },{ "type":"facebook-login", "cos
this.webCustomAlert
,this.webCustomAuth
,this.webcustomecomerce
组合成一个对象。它们都具有共同的性质。因此,我想从以下几点开始:
webCustomAuth
[{ "type":"google-login", "cost":30, "buildTime":2 },{ "type":"twitter-login", "cost":30, "buildTime":2 },{ "type":"facebook-login", "cost":30, "buildTime":2 }]
webCustomAlert
[{ "type":"desktop-notifications", "cost":30, "buildTime":2 },{ "type":"web-notification-page", "cost":30, "buildTime":2 },{ "type":"web-notification-settings", "cost":30, "buildTime":2 }]
网络定制商务
[{ "type":"affiliate-url", "cost":30, "buildTime":2 },{ "type":"coupons", "cost":30, "buildTime":2 },{ "type":"discounts", "cost":30, "buildTime":2 }]
到
webCustomFeatures
[{ "type":"affiliate-url", "cost":30, "buildTime":2 },{ "type":"coupons", "cost":30, "buildTime":2 },{ "type":"discounts", "cost":30, "buildTime":2 },{ "type":"desktop-notifications", "cost":30, "buildTime":2 },{ "type":"web-notification-page", "cost":30, "buildTime":2 },{ "type":"web-notification-settings", "cost":30, "buildTime":2 },{ "type":"google-login", "cost":30, "buildTime":2 },{ "type":"twitter-login", "cost":30, "buildTime":2 },{ "type":"facebook-login", "cost":30, "buildTime":2 }]
这是我的密码:
public webCustomFeatures: any;
public webCustomAlert: any;
private webCustomAlertDataPath = './assets/data/web-custom-alert.json';
public webCustomAuth: any;
private webCustomAuthDataPath = './assets/data/web-custom-auth.json';
public webCustomEcommerce: any;
private webCustomEcommerceDataPath = './assets/data/web-custom-ecommercejson';
constructor(
public httpClient: HttpClient
) {
this.webCustom = this.httpClient.get(this.webCustomDataPath);
this.webCustomAlert = this.httpClient.get(this.webCustomAlertDataPath);
this.webCustomAuth = this.httpClient.get(this.webCustomAuthDataPath);
this.webCustomEcommerce = this.httpClient.get(this.webCustomEcommerceDataPath);
}
public getAllWebCustomAlert(): Observable<any> {
return this.webCustomAlert;
}
public getAllWebCustomAuth(): Observable<any> {
return this.webCustomAuth;
}
public getAllWebCustomEcommerce(): Observable<any> {
return this.webCustomEcommerce;
}
public getAllWebCustomFeatures(): Observable<any> {
const webCustomFeatures = [];
webCustomFeatures.push(this.webCustomAlert);
webCustomFeatures.push(this.webCustomAuth);
webCustomFeatures.push(this.webCustomEcommerce);
return webCustomFeatures;
}
公共网络自定义功能:任意;
公共网络客户:任何;
私有webCustomAlertDataPath='./assets/data/web custom alert.json';
公共网络自定义权限:任何;
私有webCustomAuthDataPath='./assets/data/web自定义auth.json';
公共网络定制商务:任何;
私有webCustomEcommerceDataPath='./assets/data/web自定义电子商务JSON';
建造师(
公共httpClient:httpClient
) {
this.webCustom=this.httpClient.get(this.webCustomDataPath);
this.webCustomAlert=this.httpClient.get(this.webcustomalertdata路径);
this.webCustomAuth=this.httpClient.get(this.webCustomAuthDataPath);
this.webcustomecomerce=this.httpClient.get(this.webcustomecomercedatapath);
}
public getAllWebCustomAlert():可观察{
返回此.webCustomAlert;
}
public getAllWebCustomAuth():可观察{
返回此.webCustomAuth;
}
public getAllWebCustomEcommerce():可观察{
返回此网页。webCustomEcommerce;
}
public getAllWebCustomFeatures():可观察{
const webCustomFeatures=[];
推送(this.webCustomAlert);
推送(this.webCustomAuth);
webCustomFeatures.push(this.webcustomecomerce);
返回webCustomFeatures;
}
我一直收到错误消息
类型“any[]”不能分配给类型“Observable”。类型“any[]”中缺少属性“\u isScalar”。
如果返回的是一个不可观测的可观测数组,则要组合相关测试
public getAllWebCustomFeatures(): Observable<any> {
return combineLatest(this.webCustomAlert, this.webCustomAuth, this.webCustomEcommerce);
}
getAllWebCustomFeatures().subscribe(([webCustomAlert, webCustomAuth, webCustomEcommerce]) => {
//Do stuff with the destructured values here
});