我有一个自定义Durandal viewmodel 具有以下方法:
customModalNewMetric.show(someid);
在我的 CustomModalNewMetric
View 模型中,该方法如下所示:
CustomModalNewMetric.show = function(someid) {
return dialog.show(new CustomModalNewMetric(someid));
};
在 dialog.show
函数完成后如何执行某些函数?我想在对话框显示后执行一些 jQuery。
最佳答案
Durandal 的dialog.show()
返回一个 promise
,因此您需要做的就是以下操作:
CustomModalNewMetric.show = function(someid) {
return dialog.show(new CustomModalNewMetric(someid)).then(function(data) {
//callback function here (called after dialog is closed)
//also will return any passed data
});
}
注意:使用 durandal 时,请确保:
- 使用 requirejs 定义所有模块
- 检查控制台中是否有任何错误。
编辑(2013 年 12 月 24 日):
我遇到了this example ,与 source code这说明了我提供的答案。
如果您还有其他问题,请告诉我!
关于javascript - Durandal 模态回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20718065/