我对Durandal有问题。我像文档一样工作,并得到错误消息,即未定义函数,我该怎么办?
backend.js:
define(function(require){
return {
getActivePeriods:function(){
$.getJSON("files/ajax.php?q=getActivePeriods", function(data){
return data;
});
}
};
});
period.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
这是怎么了,有人可以帮我吗?谢谢!
最佳答案
您应该从后端文件中的函数返回promise
getActivePeriods:function(){
return $.getJSON("files/ajax.php?q=getActivePeriods");
}