相互参照している 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 は定義されていません)。
これは既知の問題ですか? その場合: どうすれば回避できますか?
この質問はデュランダルの Google グループにも投稿しました
ありがとう