目前我在激活方法中有一个从休息服务获取数据的方法,问题是视图正在等待承诺完成,如何在不阻塞激活方法的情况下加载视图并获取数据
var activate = function() {
datacontext.PersonData().then(function(result) {
name(result.person.firstName + " " + result.person.lastName);
if (result.person.gender != undefined) {
sex("(" + result.person.gender.substr(0, 1) + ")");
}
dob(generalFunctions.convertTimeStamp(result.person.birthDate, false));
inss(result.person.inss);
});
}
return { activate: activate }
完整代码 -->
define(['durandal/app',
'knockout',
'core/config',
'services/datacontext',
'core/generalFunctions'],
function (app, ko, config, datacontext, generalFunctions) {
var name = ko.observable();
var sex = ko.observable();
var dob = ko.observable();
var inss = ko.observable();
var address = ko.observable();
var city = ko.observable();
var phone = ko.observable();
var personIsSelected = ko.observable(false);
var personIsNotSelected = ko.observable(false);
var activate = function (id) {
config.isLoading(false);
if (id == null) {
if (config.selectedPatientId().length == 0) {
personIsNotSelected(true);
personIsSelected(false);
} else {
personIsNotSelected(false);
personIsSelected(true);
}
} else {
config.selectedPatientId(id);
personIsSelected(true);
personIsNotSelected(false);
}
config.pageTitle("Dashboard");
setDashboardData();
};
var setDashboardData = function () {
var id = config.selectedPatientId();
//Fill basc patient data
datacontext.patientBasicData(id).then(function(result) {
name(result.person.firstName + " " + result.person.lastName);
if (result.person.gender != undefined) {
sex("(" + result.person.gender.substr(0, 1) + ")");
}
dob(generalFunctions.convertTimeStamp(result.person.birthDate, false));
inss(result.person.inss);
});
//Fill adresss
datacontext.patientAddress(id).then(function(result) {
var firstAdress = result[0];
address(firstAdress.street);
city(firstAdress.zip + " " + firstAdress.municipality);
phone(firstAdress.cellPhoneNumber);
});
//datacontext.medicationEntries(id).then(function (result) {
// console.log("medicationEntries");
// console.log(result);
//});
//datacontext.careElements(id).then(function (result) {
// console.log("CareElements");
// console.log(result);
//});
};
var vm = {
personIsSelected: personIsSelected,
personIsNotSelected: personIsNotSelected,
name: name,
sex: sex,
dob: dob,
inss: inss,
address: address,
city: city,
phone: phone,
activate: activate,
};
return vm;
});