在下面的Alt Actions代碼中,如何在addCharacter成功後調用getCharacters()?基本上我試圖在保存新記錄到數據庫後刷新字符列表。React Js ALT - 調用另一個成功的函數
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);
})
}
STORE
getCharactersSuccess(res) {
this.setState({
characters: res
})
}
檢查這一個,可能會有所幫助:http://stackoverflow.com/questions/34370957/bluebird-warning-a-promise-was-created-in-a-handler-but-was-not-從我 –