我有一个Aurelia网络应用程序,通过名称搜索艺术家,然后返回艺术家的所有艺术作品。由艺术家搜索返回的JSON类似于这样:Aurelia - 将来自两个API调用的json合并为一个
{
"source": "Museum",
"language": "EN",
"resultsCount": 1,
"objects": [
{
"objectNumber": "125.1988",
"objectID": 981,
"title": "Governor's Palace (Raj Bhaven) project, Chandigarh, India",
"displayName": "Le Corbusier (Charles-Édouard Jeanneret)",
"alphaSort": "Le Corbusier (Charles-Édouard Jeanneret)",
"artistID": 3426,
"displayDate": "French, born Switzerland. 1887–1965",
"dated": "1951–1976",
"dateBegin": 1951,
"dateEnd": 1976,
"medium": "Wood, cardboard, and plexiglass",
"dimensions": "33 x 71 1/4 x 65\" (83.8 x 181 x 165.1 cm)",
"department": "Architecture & Design",
"classification": "A&D Architectural Model",
"onView": 0,
"provenance": "",
etc....
的完整JSON是在这里:
https://github.com/smoore4moma/tms-api/blob/master/object.json
我的问题是,艺术家搜索可以返回多个艺术家与同类名称(例如“Serra”返回Richard Serra和Daniel Serra-Badué)。因此,我可以循环搜索并调用API两次以获取艺术作品,但我还没有找到将两种不同的API调用结合起来的方法,而不是与Aurelia无关。这是我正在尝试做的一个代码片段。我试过jQuery,.extend,.concat,.push,创建数组,字典....我只是卡住了。
getByConstituentId(id) {
return this.http.fetch(baseUrl + "/artists/" + id + token)
.then(response => response.json())
.then(response => {
return response.objects;
});
}
// This is not the actual looping code. But the idea is to combine these two function calls into one result and return that.
getBySearchTerms(searchCreator) {
let obj0 = this.getByConstituentId(5350);
let obj1 = this.getByConstituentId(5349);
return ??? // This is where I am looking for help.
// just for ex. "return this.getByConstituentId(5349);"
// works just fine
}
有关如何做到这一点的任何建议?否则,我将构建一个采用一组艺术家ID的API方法,但我宁愿使用简单的API方法并在需要时组合json。谢谢。
的后续
继@Tomalak的意见,这是最终什么工作:
return Promise.all([
this.getByConstituentId(5349),
this.getByConstituentId(5350)])
.then(response => {
return response[0].concat(response[1]);
});
请不要张贴代码的截图,这没有任何意义。 – Tomalak
我看到有关不张贴网址的常见评论,因为它可能会变成一个死链接有一天...所以这是它? – smoore4
很明显,邮政编码为文本。 – Tomalak