0

Durandal에 문제가 있습니다. 나는 워드 프로세서처럼 작동하고 에러를 얻었고, 함수는 정의되지 않았으며, 무엇이 잘못 되었습니까?Durandal 함수가 정의되지 않았습니다.

backend.js :

define(function(require){ 
    return { 
     getActivePeriods:function(){ 
      $.getJSON("files/ajax.php?q=getActivePeriods", function(data){ 
       return data; 
      }); 
     } 
    }; 
}); 

periods.js :

define(function (require) { 
     var backend = require('backend'); 
     var ko = require('knockout'); 

     return { 
      active_periods:ko.observableArray([]), 
      activate:function(){ 
       var that = this; 
       backend.getActivePeriods().then(function(results){ 
        that.active_periods(results); 
       }); 
      } 
     }; 
    }); 

오류 :

여기에 잘못된 무엇
ERROR: backend.getActivePeriods(...) is undefined 
TypeError: backend.getActivePeriods(...) is undefined 

, 나를 anybodyhelps 수 있습니까? 고마워!

+0

당신이'$ .getJSON()'의 앞에'return'을 넣어 잊어 버리셨습니까? 비동기 함수와 약속이 작동하는 방법을 읽어야합니다. – Brett

답변

2

당신은 백엔드 파일에 함수에서 약속을 반환해야

getActivePeriods:function(){ 
      return $.getJSON("files/ajax.php?q=getActivePeriods"); 

     } 
+0

Thx, 이제 작동합니다. – fibi

관련 문제