在RxJS 6中,如何使用诺言链接和传递数据?我必须使用jira-connector npm库连续执行一堆JIRA api调用。但是我不确定如何执行数据并将其传递给函数。
谢谢!
例如:
const pipeData = Observable.from(jira.search.search({
jql: 'team = 41 and type = "Initiative"'
}))
pipeData.pipe(
data => operators.flatMap(data.issues),
issue => Observable.from(jira.search.search({
jql: `team = 41 and "Parent Link" = ${issue.key}`
}))).subscribe(results => {
console.log(results)
})
答案 0 :(得分:1)
首先,必须在管道函数中使用 lettable 运算符。
您要尝试执行的操作是:
类似这样:
pipeData.pipe(
// when pipeData emits, subscribe to the following and cancel the previous subscription if there was one:
switchMap(data => of(data.issues))),
// now you get array of issues, so concatAll and get a stream of it:
concatAll(),
// now to call another HTTP call for every emit, use concatMap:
concatMap(issue => jira.search.search({
jql: `team = 41 and "Parent Link" = ${issue.key}`
})).subscribe(results => {
console.log(results)
})
请注意,我没有将jira.search.search
用from
包裹起来,因为您还可以将promise传递到concatMap
中,还可以传递第二个参数- resultSelector 函数,仅在需要时选择一些属性:
concatMap(issue => jira.search.search({
jql: `team = 41 and "Parent Link" = ${issue.key}`),
result => result.prop1
)