我有这样的 Shell html
<div data-bind="compose: { model: 'ui/user/viewmodels/header', view: 'infoveave/user/views/header'}"></div>
<div class="container-fluid page-host">
<!--ko compose: {
model: router.activeItem,
afterCompose: router.afterCompose,
transition:'entrance'
}--><!--/ko-->
</div>
和 shell js 一样
define(function(require) {
var router = require('durandal/plugins/router'),
system = require('durandal/system'),
return {
router: router,
activate: function () {
var self = this;
router.mapAuto('ui/user/viewmodels');
system.log('Sheel Activate Called');
return router.activate('dashboard');
}
};
});
问题是标题上的激活函数没有被调用,但仪表板上的那个被调用,我必须在标题中获取一些 ajax 内容并绑定它,我该如何实现
我想保持这个逻辑分开,因为我不希望我的外壳有这个逻辑
供参考我的标题(为了简化我已经将我的复杂模型转换为一个简单的可观察的
define(function (require) {
var router = require('durandal/plugins/router'),
system = require('durandal/system');
this.userInfo = ko.observable('');
return {
router: router,
activate: function () {
system.log('Got Called Now');
//do some ajax stuff here and update userinfo
}
};
});
header html 的最简单形式是
<span class="dropdown-notif" data-bind="text: userInfo"></span>