1

私はこのようなシェル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>

とシェル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
    }
};
});

ヘッダーhtmlの最も単純な形式は

<span class="dropdown-notif" data-bind="text: userInfo"></span>
4

3 に答える 3

7

ヘッダー ビュー モデルを有効にしているとは思いません。

次のように、ヘッダー ビュー構成バインディングに「activate:true」を追加してみてください。

<div data-bind="compose: { 
    model: 'ui/user/viewmodels/header', 
    view: 'infoveave/user/views/header', 
    activate: true}">
</div>
于 2013-03-07T13:39:24.740 に答える
1

これはあなたの問題でしょうか?: 「アクティベーターが存在するか、作成バインドで activate:true が設定されていない限り、アクティベーター コールバックは実行されません。」

ソース: http://durandaljs.com/documentation/Hooking-Lifecycle-Callbacks/

于 2013-07-10T15:14:44.353 に答える
0

ブラウザのコンソールウィンドウにエラーが表示されますか?(ChromeでF12キーを押してから、[コンソール]タブをクリックします)。

ビューモデルのアクティブ化を妨げるエラーが発生する可能性があります。それ以外の場合は、次の変更を試すことができます。

シェル:

define(function(require) {
    var router = require('durandal/plugins/router'),
        system = require('durandal/system'); // note the semi colon here

    return {
        router: router,
        activate: function () {
            var self = this;
            router.mapAuto('ui/user/viewmodels');
            // the line below to map the route to your view model may be required
            router.mapRoute('dashboard');
            system.log('Sheel Activate Called');
            return router.activate('dashboard');
        };
    };
});

ヘッダービューモデル:

define(function (require) {
    var router = require('durandal/plugins/router'),
        system = require('durandal/system');

    var userInfo = ko.observable('');

    return {
        router: router,
        userInfo: userInfo, // putting the property here should make it visible to the binding in the view
        activate: function () {
             system.log('Got Called Now');
             //do some ajax stuff here and update userinfo
        }
    };
});
于 2013-03-05T15:26:49.577 に答える