I have a problem with Durandal. I worked like the docs and getting the error, that the function is not defined, what do I wrong?
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:
ERROR: backend.getActivePeriods(...) is undefined
TypeError: backend.getActivePeriods(...) is undefined
What's here wrong, can anybodyhelps me? Thx!
return
in front of$.getJSON()
? You should read up on how asynchronous functions and promises work. – Brett