동일한 도구 (knockout 및 bootstrap3)를 사용하고 있습니다. 이것은 내가 예를 들어 조동사를 달성하는 방법입니다
이 사업부 내 index.html을에서 신체의 첫 번째 요소로 존재 :
<div class="modal fade" id="BaseModal" tabindex="-1" role="dialog" aria-labelledby="BaseModal" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div id="modalLoading" class="ajax-loader">
<img src="images/working_blue.gif" />
</div>
<div class="modal-dialog modal-lg">
<div id="ModalAnchor" class="modal-content col-lg-4 col-lg-offset-4" data-bind="html: $data.ModalContent"></div>
</div>
</div>
// This is typescript but the javascript should be pretty close to this.
private LoadModalView(viewName: string, viewModel: any): void {
$.get(viewName)
.then((view: any, status: string, jxhr: JQueryXHR) => {
this.ModalContent(''); // ensure there is no content in the modal.
this.ModalContent(view); // Load new HTML
ko.applyBindingsToDescendants(viewModel, this.ModalAnchor[0]); // bind new modal viewmodel
this.BaseModal.modal('show'); // Open the modal
}, (view: any, status: string, jxhr: JQueryXHR) => { /*Do error handling*/ });
}
편집 : 저는 여기에로드 HTML의 예입니다 모달 다음 LoadModalView 함수에서
<div class="modal-header">
<h3 data-bind="text: $data.Header"></h3>
</div>
<div class="modal-body">
<h5 data-bind="text: $data.Message"></h5>
</div>
<div class="modal-footer">
<button id="OK" class="btn btn-primary center-block" data-bind="click: OK, text: ButtonText" />
</div>
는 뷰 모델 파라미터는 새로운 모달 등의 새로운 데이터/콘텐츠/표현하는 뷰 모델이다.
모달 뷰 모델에서는 모달에 목적이있는 경우 '숨기기'를 호출합니다.
도움이 되었기를 바랍니다. 이 작업을 수행하는 데 '올바른'방법인지 '적절한 방법인지 모릅니다. 그러나 이것이 내 패턴입니다.
나는 실제로 이것을 알아 냈습니다. 더 많은 방법에 대해 ... 그러나 이것도 작동합니다 ... 그리고 대답으로 간주되어야합니다. 이것이 매우 흔한 일이되어야한다는 것을 알기에, 나는 녹아웃이 이것을 위해 문서화해야한다고 생각한다. – Ronnyek