我有一個使用DurandalJS和KnockoutJS的SPA。在我的初始頁面上,我允許點擊一個項目,然後加載該項目的輔助頁面。這是我進入二級頁面:Knockout applyBindings錯誤
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;
});
在此先感謝您的幫助。