【发布时间】:2017-05-06 11:02:50
【问题描述】:
我有 3 个如下所示的可观察数组。
persons = [
{
"firstName":"john",
"lastName":"public",
"locationID":"1",
"departmentID":"100"
},
{
"firstName":"sam",
"lastName":"smith",
"locationID":"2",
"departmentID":"101"
}
]
departments = [{"departmentID": "100",
"name": "development"
},
{"departmentID": "101",
"name": "sales"
}]
locations = [{"locationID": "1", "name": "chicago"},
{"locationID":"2", "name": "ny"}]
我正在尝试将这 3 个组合到以下结果中,
result = [
{
"firstName":"john",
"lastName":"public",
"location":"development",
"department":"sales"
},
{
"firstName":"sam",
"lastName":"smith",
"location":"ny",
"department":"sales"
}
]
为了得到想要的结果,我对可观察的人使用了 map 函数来提供新的对象数组。
this.store<Person>('persons')
.map(function(person){
let p = new personDetail()
p.firstName = person.firstName,
p.lastName = person.lastName
return p;
})
PersonDetail 对象具有firstName、lastName、location 和department 属性。如何查找部门 observable 并获取 departmentID 的匹配行以获取部门名称?
我是 rxjs 库的新手,如果有更好的方法来获得所需的结果,请告诉我。
【问题讨论】:
标签: javascript angular typescript rxjs rxjs5