Durandal ViewModels在2.0.0升级后重复激活

Durandal ViewModels在2.0.0升级后重复激活,durandal,Durandal,我正在将durandal项目从1.2.0升级到2.0.0版。我已经遵循了durandal文档()中的步骤,现在应用程序的功能与往常一样。我所看到的问题是,我的激活回调不断地被调用 以下是正在执行此操作的viewmodels之一: define(['services/datacontext', 'plugins/router', 'services/logger', 'services/model', 'services/images', 'services/pager'], functi

我正在将durandal项目从1.2.0升级到2.0.0版。我已经遵循了durandal文档()中的步骤,现在应用程序的功能与往常一样。我所看到的问题是,我的激活回调不断地被调用

以下是正在执行此操作的viewmodels之一:

define(['services/datacontext', 'plugins/router', 'services/logger', 'services/model', 'services/images', 'services/pager'],
    function (datacontext, router, logger, model, images, pager) {

        var collaborators = ko.observableArray([]);
        var filterString = ko.observable();
        var pageHandler = new pager();

        var activate = function (filter) {
            return Q.all([datacontext.getAll(model.entityNames.songwriter + 's', "", collaborators, { orderBy: "firstName" })])
                    .then(dataRetrieved)
                    .then(activatePager);

            function dataRetrieved() {
            };

            function activatePager() {
                pageHandler.init.call(pageHandler, collaborators(), {
                    pageSize: 12,
                    filterCallback: function (item) {
                        var filter = filterString().toLowerCase();

                        var pred1 = item.fullName().toLowerCase().indexOf(filter) >= 0;

                        return pred1;
                    }
                });
                if (filter != null) {
                    filterString(filter);
                    pageHandler.applyFilter.call(pageHandler);
                }
            };
        };

        var deactivate = function () {
        };

        var vm = {
            activate: activate,
            deactivate: deactivate,
            collaborators: pageHandler.displayItems,
            title: 'Collaborators',
            images: images,
            router: router,
            pager: pageHandler,
            filterString: filterString
        };

        return vm;
    });
以前有人见过这个吗

以下是chrome控制台输出:

编辑
这似乎不是在所有viewmodels上都会发生,这一个很好

define(['durandal/app', 'services/datacontext', 'plugins/router', 'services/logger', 'services/model', 'viewmodels/shared/leftnav', 'viewmodels/modals/imagecrop', 'services/images'],
    function (app, datacontext, router, logger, model, leftnav, imagecrop, images) {
        leftnav.area("Songwriter");

        var songwriter = ko.observable();
        var songwriterId = ko.observable();
        var publishers = ko.observableArray([]);
        var pros = ko.observableArray([]);

        var activate = function (id) {
            songwriterId(id);
            leftnav.entityId(songwriterId());

            return Q.all([datacontext.getEntityById(model.entityNames.songwriter, songwriterId(), "Publisher, Pro", songwriter),
                          datacontext.getAll(model.entityNames.publisher + 's', "", publishers),
                          datacontext.getAll(model.entityNames.pro + 's', "", pros)]);
        };

        var deactivate = function () {
            if (datacontext.hasChanges()) {
                datacontext.cancelChanges();
            }
        };

        var saveClick = function () {
            datacontext.saveChanges().then(saveComplete);

            function saveComplete() {
                router.navigateBack();
            };
        };

        var cancelClick = function () {
            router.navigateBack();
        };

        var imageUploaded = function (e) {
            logger.logSuccess("Image Uploaded Successfully", e.response, "Profile", true);
            songwriter().photoFilePath('/azure/profileimages/' + e.response);

            app.showDialog(imagecrop, {
                title: 'Crop Profile Image',
                message: '<i class="icon-info-sign"></i> Your profile image needs to be cropped to ensure that it does not appear distorted.',
                filePath: songwriter().photoFilePath()
            }).then(appendCropInfo);

            function appendCropInfo(coords) {
                var path = songwriter().photoFilePath;

                path(path() + '?crop=(' + coords.x + ',' + coords.y + ',' + coords.x2 + ',' + coords.y2 + ')');
            };
        };


        var vm = {
            activate: activate,
            deactivate: deactivate,
            songwriter: songwriter,
            publishers: publishers,
            pros: pros,
            title: 'Songwriter',
            cancelClick: cancelClick,
            saveClick: saveClick,
            imageUploaded: imageUploaded,
            images: images
        };

        return vm;
    });
编辑-路线

activate (details.js:11)
invoke (activator.js:52)
activate (activator.js:99)
(anonymous function) (activator.js:308)
(anonymous function) (jquery-2.0.3.js:3070)
fire (jquery-2.0.3.js:2914)
self.add (jquery-2.0.3.js:2960)
(anonymous function) (jquery-2.0.3.js:3069)
jQuery.extend.each (jquery-2.0.3.js:590)
(anonymous function) (jquery-2.0.3.js:3065)
jQuery.extend.Deferred (jquery-2.0.3.js:3126)
promise.then (jquery-2.0.3.js:3064)
(anonymous function) (activator.js:306)
(anonymous function) (jquery-2.0.3.js:3070)
fire (jquery-2.0.3.js:2914)
self.add (jquery-2.0.3.js:2960)
(anonymous function) (jquery-2.0.3.js:3069)
jQuery.extend.each (jquery-2.0.3.js:590)
(anonymous function) (jquery-2.0.3.js:3065)
jQuery.extend.Deferred (jquery-2.0.3.js:3126)
promise.then (jquery-2.0.3.js:3064)
(anonymous function) (activator.js:302)
(anonymous function) (jquery-2.0.3.js:3070)
fire (jquery-2.0.3.js:2914)
self.add (jquery-2.0.3.js:2960)
(anonymous function) (jquery-2.0.3.js:3069)
jQuery.extend.each (jquery-2.0.3.js:590)
(anonymous function) (jquery-2.0.3.js:3065)
jQuery.extend.Deferred (jquery-2.0.3.js:3126)
promise.then (jquery-2.0.3.js:3064)
(anonymous function) (activator.js:300)
jQuery.extend.Deferred (jquery-2.0.3.js:3126)
system.defer (system.js:218)
computed.activateItem (activator.js:285)
activateRoute (router.js:248)
handleGuardedRoute (router.js:303)
ensureActivation (router.js:313)
(anonymous function) (router.js:357)
(anonymous function) (jquery-2.0.3.js:3070)
fire (jquery-2.0.3.js:2914)
self.fireWith (jquery-2.0.3.js:3026)
deferred.(anonymous function) (jquery-2.0.3.js:3115)
(anonymous function) (system.js:256)
路由配置如下:

{ route: 'songwriter/:id', moduleId: 'songwriter/details', nav: true, title: 'Profile', settings: { icon: 'icon-edit' } },

可能是升级到2.0后我观察到的相同问题。 我在Durandal Google group发布了一个类似的案例:


我创建了一个repo来重现这个问题:

第一个视图模型是如何组成的?是局部视图、模态对话框等吗?第一个视图模型是全视图。它和第二个一样,很难说。有很多代码缺失,我只能猜测它在做什么。添加
调试器作为
activate()
函数的第一行,并逐步遍历代码以找出触发它的原因。是的,不幸的是,这是一个庞大项目的一部分。我已经添加了调试器语句,但是,我无法确定是什么导致它循环。您使用的是子路由器吗?是的,这看起来是相同的问题。在解决方案方面取得了任何进展吗?是的,这是Durandal 2中的一个缺陷。见最近的评论: