【问题标题】:Durandal 2.1 - accessing view from viewmodel?Durandal 2.1 - 从视图模型访问视图?
【发布时间】:2014-08-15 03:13:56
【问题描述】:

我的视图模型中有以下内容:

 dialog.getContext().reposition(vm);

但这不起作用,因为我应该通过view,而不是viewmodel。我如何 - 从视图模型中 - 访问其相应的视图?

【问题讨论】:

  • viewmodel中的附加函数在viewmodels对应的view中传递。

标签: durandal durandal-2.0


【解决方案1】:

从您的 viewModel 访问视图 您有 detached、compositionComplete、attached 和 compositionComplete 处理程序可供选择。

例如来自attached:

function attached(view, parent) {
   console.log("This is the current view",view);//this will log the view HTML
  $(view).find(".smallLoader").fadeOut();// Now fadeOut .smallLoader from this view
}

var viewModel = {
    activate: activate,
    title: 'Home',
    attached: attached
};

return viewModel;

【讨论】:

  • 您可以从 binding、bindingComplete、attached、compositionComplete 和 detached 访问视图。未激活
猜你喜欢
  • 1970-01-01
  • 2013-05-19
  • 1970-01-01
  • 2013-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多