1
我打电话给分机knex
,然后使用该结果拨打电话REST
与axios
。我使用的Observable
来管理整个事情。这里是我的代码不工作像我想:为什么我必须在我的Rx流中指出索引?
return Observable
.fromPromise(knex('users').where({id: userId}).select('user_name'))
.map(res => getCreatePlaylistConfig(res[0].user_name))
.concatMap(axios)
.toPromise();
function getCreatePlaylistConfig(userName) {
return {
url: 'https://api.spotify.com/v1/users/' + userName + '/playlists',
method: 'POST'
}
}
我有使用在
map
的
index
,我叫
getCreatePlaylistConfig
使代码工作
。我记录的是来自与knex
回调对象:
do(res => console.log(res)
,它看起来像这样:
[ { user_name: 'joe'} ]
它是一个数组像我所期望的,但我认为map
将遍历数组。为什么它需要index
?我如何使这段代码正常工作?