情态动词比我想象的要困难:/
让模态正确加载 View / View 模态,单击保存按钮保存信息(我确实从 Q.js 得到了“应该为空:[]”,但显然这不是问题?)我遇到的问题可能与 promise 有关,但如果是的话我找不到它。
父 View 模型 -
var createNew = function () {
app.showModal(tfcreate).then(function (modalResult) {
if (!modalResult) { return false; }
var templateId = modalResult;
router.replaceLocation('#/templateformedit/' + templateId);
});
};
Modal 的 View 模型 -
var cancel = function () {
this.modal.close(false);
};
var save = function () {
isSaving(true);
setRevisionInfo();
datacontext.saveChanges()
.then(alertMe)
.fail(initFailed)
.fin(complete);
function setRevisionInfo() {
templateForm().revisionLevel(1);
templateForm().createdById(shell.currentUser().id());
templateForm().lastRevisedId(shell.currentUser().id());
var nowDT = moment().format('LL');
templateForm().lastRevisedDT(nowDT);
templateForm().createdDT(nowDT);
}
function alertMe() {
return console.log('done'); // <<< This is firing ok
}
function complete() {
isSaving(false);
this.modal.close(templateForm().id()); // <<< Breakpoint reaches here just fine
}
};
如果我按下绑定(bind)回cancel()的取消按钮,它会很好地关闭,如果我单击保存按钮,它会点击save(),正确保存对象,并到达所有断点但永远不会关闭。如果我保存后按取消,它会再次关闭。我尝试在complete()函数期间调用cancel(),它到达了语句,但再次没有关闭。有什么想法吗???
注意:我可以从模式中调用 router.replaceLocation,它会很好地更改 View ,但模式会保留到下一个 View 。
编辑:我添加了另一个按钮“关闭”,该按钮在 isSaving 完成并且 hasChanges 为 false 之前被禁用,这让我可以关闭它,一切都很好,但这不是必需的,对吧?
最佳答案
每个请求:
您确定 complete()
中的 this
仍然是您的虚拟机上下文吗?在 save() 顶部和complete() 中尝试 var self=this;
self.modal.close(...)
关于modal-dialog - Durandal 莫代尔不会关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16322159/