1
필자가 필요로하는 것은 현재 계산 된 관측치가 적절하게 업데이트되도록 현재 경로를 모니터링하는 것입니다. 의견에 대한 설명이있는 관련 코드 :Durandal shell에서 경로를 모니터링하는 방법은 무엇입니까?
define(['durandal/plugins/router', 'durandal/app','services/dataservice'], function (router, app, dataservice) {
// TODO: I need to make these computed observables that monitor the route, but I can't monitor the route until after it's been activated, so I just define these guys as observables here
this.isViewingFolder = ko.observable();
this.isViewingSet = ko.observable();
// These don't evaluate correctly because isViewingFolder() doesn't get defined until after the DOM loads (I think)
var displayAddForFolder = ko.computed(function() {
return selectedItemsCount() == 0 && isViewingFolder() && !isViewingSet();
});
var displayAddForSet = ko.computed(function() {
return selectedItemsCount() == 0 isViewingSet() && !isViewingFolder();
});
// The ONLY way I've been able to get this to work is with the following (putting a computed into an observable??)
var viewAttached = function() {
isViewingFolder(ko.computed(function() {
return router.activeRoute().moduleId == 'viewmodels/folder';
}));
isViewingSet(ko.computed(function() {
return router.activeRoute().moduleId == 'viewmodels/set';
}));
}
// If I try this the value updates once but only once, never again:
var viewAttached = function() {
isViewingFolder(router.activeRoute().moduleId == 'viewmodels/folder');
isViewingSet(ko.computed(router.activeRoute().moduleId == 'viewmodels/set');
}
도움이 될만한 정보가 있습니다. 주말 내내 내 머리를 때렸어.
저는 어떻게 작동시키는 지 알 수 없습니다. Rainer 감사합니다. – RobVious