【发布时间】:2018-09-11 16:53:06
【问题描述】:
我一直在试图弄清楚如何使用本文档中提供的 REST api 验证用户以从 JIRA 访问 JSON 数据:https://developer.atlassian.com/server/jira/platform/jira-rest-api-example-basic-authentication-6291732/
Items 是允许我从 jira 获取由 URL 给出的 JSON 数据中的值的数组。
我无法接收数据,因为当我打印 items 变量时它似乎是空的。
任何帮助将不胜感激。
this.state = {
items: []
}
var headers = new Headers();
//test1:test1 is username and password
headers.append("Authorization", "Basic " + base64.encode("test1:test1"));
componentDidMount() {
fetch('http://ksr-ca-qmaltjira.ca.kronos.com:8061/rest/api/2/search?jql=project=SUP&maxResults=2', {headers: headers})
.then(res => res.json())
.then(json => {
this.setState({
isLoaded: true,
items: json
})
});
}
render() {
var { isLoaded, items } = this.state;
const emptyOrNot = !!items.length && !!items.length ? <p>not empty</p> :
<p>empty</p> //Checks to see if my array of items is empty
return (
{emptyOrNot}
<div className="App">
{items.map(item => (
<li >
Name: item.name
</li>
)
)}
</div>
)
}
【问题讨论】:
-
授权似乎是正确的。您还可以链接您要访问的端点的文档吗?
-
端点是什么意思,我对这些术语不太熟悉 XD
-
/rest/api/2/search是您在上面的示例中点击的 JIRA 端点
标签: javascript arrays reactjs jira