Javascript events 未激发ViewAttached事件
我使用的是durandal master details示例,它使用合成。我有一个视图模型,其中定义了一些事件Javascript events 未激发ViewAttached事件,javascript-events,single-page-application,durandal,Javascript Events,Single Page Application,Durandal,我使用的是durandal master details示例,它使用合成。我有一个视图模型,其中定义了一些事件 var ctor = function(name, description) { this.name = name; this.description = description; }; ctor.prototype.activate = function() { system.log('Model Activati
var ctor = function(name, description) {
this.name = name;
this.description = description;
};
ctor.prototype.activate = function() {
system.log('Model Activating', this);
};
ctor.prototype.deactivate = function () {
system.log('Model Deactivating', this);
};
ctor.prototype.viewAttached = function (view) {
system.log('this is not called !', this);
};
将触发除viewAttached之外的所有事件。我在这里找不到原因。如果没有更多信息,我唯一能建议检查的就是这张便条 注意:如果已将cacheViews设置为true,则仅在首次显示视图时在初始绑定时调用viewAttached,因为从技术上讲,视图仅附加一次。如果希望覆盖此行为,请在合成绑定上设置alwaysAttachView:true
尝试在绑定中设置
alwaysAttachView:true
,看看是否有效。事实上,我在GithHub存储库中使用了最新版本的Durandal。在查看合成模块后,发现他们已将其重命名为compositionComplete
。这是意料之中的事
ctor.prototype.compositionComplete= function (view) {
system.log('works!', this);
};
编辑在发布Durandal 2.0后,在文档中,我们将附加
事件,而不是viewAttached
如果您使用的是Durandal 2.0,“viewAttached”方法被重命名为“attached”。谢谢!发现了问题。。我使用的是GitHUb存储库中的最新版本。