我有一个使用 DurandalJS 和 KnockoutJS 的 SPA。在我的初始页面上,我允许单击一个项目,然后加载该项目的辅助页面。这是我访问二级页面的方式:
var goToDetails = function (selectedDailyLog) {
var url = '#/dailylog/' + selectedDailyLog.id();
//durandal/plugins/router is sammy.js
router.navigateTo(url);
};
在辅助页面上,我尝试调用 ko.applyBindings 并且不断收到以下错误:
未捕获的错误:无法解析绑定。消息:ReferenceError:未定义路由器;绑定值:foreach: router.visibleRoutes
这是辅助页面的 javascript:
define(['config', 'durandal/system', 'services/logger', 'services/dataservice'],
function (config, system, logger, dataservice) {
var owners = ko.observableArray();
var selectedOwner = ko.observable();
var dailyLog = ko.observable({ started: 'one' });
var routeCriteria;
//#region Internal Methods
function activate(routeData) {
routeCriteria = routeData;
dataservice.getOwners(owners);
logger.log('Daily Log Activated with Id: ' + routeData.id.toString(), null, 'dailylog', true);
return true;
}
var vm = {
activate: activate,
title: 'Daily Log',
owners: owners,
selectedOwner: selectedOwner,
dailyLog:dailyLog
};
ko.applyBindings(vm);
return vm;
});
在此先感谢您的帮助。