Durandal을 처음 사용하기 때문에 내 문제에 대해 잘못된 접근 방식을 취할 수 있습니다.프로그래밍 방식으로 Durandal 모달 닫기
사용자가 로그인 버튼을 클릭했을 때 '로그인 ... 기다려주십시오'라는 메시지가있는 모달 팝업을 표시하려고합니다. 응답을 받으면 모달 팝업을 닫고 싶습니다. 내 시도한 접근 방식은 Durandal의 app.showModal과 로그인 뷰 모델의 버튼이없는 뷰를 사용하여 사용자 정의 모달 팝업을 호출하는 것입니다. 이것은 모달 팝업을 보여 주지만 일단 서버 응답을 받으면 팝업을 닫는 방법을 파악할 수 없었습니다. 내가 본 모든 예제는 팝업을 닫는 모달 팝업보기에 버튼이 있습니다.
이것이 가능합니까? 그렇지 않다면 사용자에게 무언가가 일어나고있는 것을 보여주고 사용자가보기에서 다른 버튼을 사용하지 못하도록하는 더 나은 방법이 있습니까? (외부 코드 제거와 함께)
다음은 로그인 뷰의 뷰 모델 코드입니다 :
define(['services/appsecurity', 'durandal/plugins/router', 'services/utils', 'services/errorhandler', 'durandal/app', 'viewmodels/controls/activityindicator'],
function (appsecurity, router, utils, errorhandler, app, activityIndicator) {
var username = ko.observable().extend({ required: true }),
password = ko.observable().extend({ required: true, minLength: 6 }),
rememberMe = ko.observable(),
returnUrl = ko.observable(),
isRedirect = ko.observable(false),
var viewmodel = {
username: username,
password: password,
rememberMe: rememberMe,
returnUrl: returnUrl,
isRedirect: isRedirect,
appsecurity: appsecurity,
login: function() {
var credential = new appsecurity.credential(this.username(), this.password(), this.rememberMe() || false),
self = this;
activityIndicator.message = 'Logging in...please wait';
app.showModal(activityIndicator);
appsecurity.login(credential, self.returnUrl())
.fail(self.handlevalidationerrors)
.always(function() { activityIndicator.close(); });
}};
return viewmodel;
});
appsecurity.login
기능은 AJAX 포스트 호출입니다. 사용자 정의 모달의 뷰 모델은이 프로그램을 실행할 때
define(function() {
var activityIndicator = function (message, title, options) {
this.message = message;
this.title = title || activityIndicator.defaultTitle;
this.options = options || activityIndicator.defaultOptions;
this.close = function() {
this.modal.close();
};
};
return activityIndicator;
});
, 내가 close
의 .always(function() { activityIndicator.close(); });
이 정의되지에서 오류가 발생합니다.
매우 간단합니다. 코드를 게시 할 수 있으면 문장을 어디에 넣을 지 안내 할 수는 있지만 this.modal.close()를 찾고 있습니다. - 함수 내에서 this를 호출하는 경우 로그인 성공 또는 AJAX 호출 내에서 self = this와 같은 것을 사용하여 적절한 범위를 제공해야 할 수도 있습니다. 단지 이것 대신에. 이 질문을 참조하십시오 http://stackoverflow.com/questions/16322159/durandal-modal-wont-close –
어떤 Durandal 버전을 사용하고 있습니까? – Tyrsius
요청에 따라 코드를 추가했습니다. 감사. – Craig