[英]How to inject promise array inside observable array
我正在構建一個基於身份驗證的用戶菜單並且一切正常,但我有一部分菜單是從 API getMainCategories()
一個promise
類型的方法中獲得的。
我需要將來自該方法的數據注入到特定 object 的菜單數組中;
這里:
let menu: any = [
...
{
text: 'categories',
icon: 'flaticon-2-squares',
children: [] // I need to inject the categories here
},
...
];
在下面的代碼中,您會注意到我已將 promise getMainCategories
轉換為observable
,但我不知道接下來要做什么。
我的菜單代碼:
getMenu() {
const mainCategories = from(this.woo.getMainCategories());
let menu: any = [
{
text: 'home',
icon: 'flaticon-home',
path: '/tabs/home'
},
{
text: 'categories',
icon: 'flaticon-2-squares',
children: []
},
{
text: 'cart',
icon: 'flaticon-shopping-cart',
path: '/tabs/cart'
},
{
text: 'chechout',
icon: 'flaticon-shopping-bag',
path: '/checkout'
}
];
const loggedInMenu = [
{
text: 'My Account',
icon: 'flaticon-login',
path: '/tabs/profile'
}
];
const loggedOutMenu = [
{
text: 'login',
icon: 'flaticon-login',
path: '/login'
},
{
text: 'register',
icon: 'flaticon-login',
path: '/register'
}
];
const menu$ = this.isUserLoggedIn.pipe(
switchMap(
status => {
if (status) {
return of(menu.concat(loggedInMenu))
} else {
return of(menu.concat(loggedOutMenu))
}
}
)
);
return menu$;
}
我不知道“的”是什么。 但我認為您可能希望讓 menu.children.concat(loggedXXXMenu) 而不是 menu.concat。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.