Javascript 连锁经营
我有一个函数 const func=>server.insertPatientServeyQuestionToDatabaseStore.getPatientID、SurveyNumber、Store.getPatientQuestion 这就是所谓的 在此之后,有一个函数:Javascript 连锁经营,javascript,promise,chaining,Javascript,Promise,Chaining,我有一个函数 const func=>server.insertPatientServeyQuestionToDatabaseStore.getPatientID、SurveyNumber、Store.getPatientQuestion 这就是所谓的 在此之后,有一个函数: const promise = server.GetPatientHistoryData(Store.getPatientID()) .then( response => Dispatche
const promise =
server.GetPatientHistoryData(Store.getPatientID())
.then(
response => Dispatcher.dispatch({
actionType: Constants.CHANGE_PATIENT_HISTORY,
payload:response}))
.catch(error => {console.log(error)});
我这样做,我认为这应该是可行的:
func().then(response => promise())
但它返回一个不可读取的属性,然后是未定义的。我的印象是这可以奏效。如何将函数链接到承诺?这会导致此错误,因为func不返回承诺。如果本部分为承诺:
server.insertPatientSurveyQuestionToDataBase(Store.getPatientID(), SurveyNumber, Store.getPatientQuestion());
您需要在func中返回它:
然后您可以像这样安全地使用它:
func().then(response => promise());
func().then(response => promise());