Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 连锁经营_Javascript_Promise_Chaining - Fatal编程技术网

Javascript 连锁经营

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 func=>server.insertPatientServeyQuestionToDatabaseStore.getPatientID、SurveyNumber、Store.getPatientQuestion

这就是所谓的

在此之后,有一个函数:

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());