您好我试图在JavaScript中找到对象数组中的布尔值的总和
我的json喜欢
var myoBj = [{
"id": 1,
"day": 1,
"status": true
}, {
"id": 2,
"day": 1,
"status": false
}, {
"id": 3,
"day": 1,
"status": false
}, {
"id": 4,
"day": 3,
"status": false
}];
Run Code Online (Sandbox Code Playgroud)
我希望使用JavaScript/typescript中的reduce函数来计算所有状态值的总和
我希望只有当所有状态都为真时才显示整体状态为真,否则它应该为假
javascript arrays javascript-objects typescript typescript2.0
我是Typescript的新手.我想从observable中选择id
这是我的观察
let myObj = [{
"id": 1,
"text": "Mary"
}, {
"id": 2,
"text": "Nancy"
}, {
"id": 3,
"text": "Paul"
}, {
"id": 4,
"text": "Cheryl"
}, {
"id": 5,
"text": "Frances"
}]
Run Code Online (Sandbox Code Playgroud)
预期结果 :
let selectedIds = [1,2,3,4,5];
Run Code Online (Sandbox Code Playgroud)
我可以在不创建数组并在for循环中推送id的情况下执行此操作.
如何从父组件以及子路由获取RouteParams
export const routes: Routes = [
{ path: '', redirectTo: 'list', pathMatch: 'full' },
{ path: 'list', component: UsersComponent },
{
path: ':id', component: UserDetailComponent,
children: [
// { path: '', redirectTo: 'overview', pathMatch: 'full' },
{ path: 'overview', component: UserInfoComponent },
{ path: 'specs/:id', component: UserProfileComponent }
]
}
];
Run Code Online (Sandbox Code Playgroud)
在组件中
export class UserDetailComponent implements OnInit {
constructor(private route: ActivatedRoute) { }
ngOnInit() {
this.route.parent.params.subscribe( (c) => {
console.log(c['id']);
});
this.route.params.subscribe(params => {
console.log(params['id']);
});
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我的路线被激活时,我总是得到不确定.请帮助解决这个问题? …