我有 2 个相互交叉引用的模型。这可能看起来像这样:
主要型号:
define(
    [ 'durandal/app', 'durandal/plugins/router', 'models/Shell', 'models/EditModel' ],
    function (app, router, shell, editModel) {
        //...
        return {
            //...
            // This function should be accessible by the EditModel 
            update: function() {
                //...
            },
            showEditView: function() {
                // Initialise the EditModel with some data and show the according view afterwards
                editModel.init('set some important stuff here...');
                router.navigateTo('#/EditView');
            }
            //...
        };
    }
);
编辑模型:
define(
    [ 'durandal/app', 'durandal/plugins/router', 'models/Shell', 'models/MainModel' ],
    function (app, router, shell, mainModel) {
        //...
        return {
            //...
            // This function should be accessible by the MainModel 
            init: function() {
                //...
            },
            showMainView: function() {
                // Update the the MainModel with some data and show the according view afterwards
                mainModel.update('set new data here...');
                router.navigateTo('#/MainView');
            }
            //...
        };
    }
);
不幸的是,这不起作用。如果我在 MainView 上加载我的页面并调用 showEditView,则变量 editView 是已知的,并且一切正常,但是 EditModel 中的变量 mainModel 未定义,因此调用mainModel.update(...)失败。如果我在 EditView 上加载页面但以“相反方向”加载页面,也会发生同样的事情(EditModel 中的 var mainModel 是已知的,但 MainModel 中的 editModel 是未定义的)。
这是一个已知问题吗?如果是这样:我该如何规避它?
我还在Durandals Google Group中发布了这个问题
谢谢