【发布时间】:2017-08-28 00:57:17
【问题描述】:
在下面的 Alt Actions 代码中,如何在 addCharacter 成功后调用 getCharacters()?基本上我在将新记录保存到数据库后尝试刷新字符列表。
getCharacters() {
requestPromise('http://localhost:3100/api/characters')
.then((res) => {
console.log("Getting Characters");
var opdata = JSON.parse(res);
this.actions.getCharactersSuccess(opdata.characters);
}).catch((err) => {
console.log('error:', err);
this.actions.getCharactersFail(err)
})
}
addCharacter(data) {
var options = {
method: 'POST',
uri: 'http://localhost:3100/api/characters/add/',
json: true,
body: {
name: data.charName,
allegiance: data.charAllegiance,
},
};
requestPromise(options)
.then((res) => {
// How can I recall getCharacters() from here
}).catch((err) => {
console.log('error:', err);
})
}
商店
getCharactersSuccess(res) {
this.setState({
characters: res
})
}
【问题讨论】:
-
检查这个,可能会有所帮助:stackoverflow.com/questions/34370957/…
标签: mongodb reactjs mongoose alt