这是我的代码,
fetch('/auth', {
credentials: 'include',
mode: 'cors'
}) // or whatever URL you want
.then((response) => response.json())
.then((data) => {
console.log(data.token + ' ' + data.username);
this.setState({
token: data.token,
username: data.username
})
return fetch("/api/openshift/projects?token=" + this.state.token + "&username=" + this.state.username,
{
credentials: 'include',
mode: 'cors'
})
})
.then((response) => response.json())
.then(
(result) => {
this.setState({
isLoaded: true,
fetchInProgress: false,
data: result.map(project => createData(project.project_name, project.project_description, project.creation_time, 'Launch'))
});
return fetch("/api/openshift/project/getimage?token=" + this.state.token,
{
credentials: 'include',
mode: 'cors'
})
},
(error) => {
this.setState({
isLoaded: true,
error
});
}
)
.then(res => res.json())
.then(
(result) => {
this.setState({
isLoaded: true,
fetchInProgress: false,
images: JSON.parse(JSON.stringify(result))
});
console.log('images' + result);
},
(error) => {
this.setState({
isLoaded: true,
error
});
}
)
}
问题是,我正在调用嵌套提取API。前两次,提取正常,但第三次,/api/openshift/project/getimage?token=
,当我调用此api时,我得到一个空的result
。
同样的代码在localhost上也能正常工作,但是当我将代码推送到服务器(在我们的例子中为openshift)时,第三个api无法正常工作。
为什么在第三种情况下第三次提取不起作用?
错误详细信息:
{this.props.imagesarray.filter(image => (image.image_name =='algo'))[0].tags.map(option => (
<MenuItem key={option.name} value={option.name}>
{option.name}
我在浏览器上看到的错误是这样的:
TypeError: Cannot read property 'tags' of undefined