我在VS 2012中使用hottowel 2.0.1创建了一个项目,并在HotTowel课程/示例之后使用以下代码。但是我得到了以下错误。
未捕获TypeError:对象#没有方法'navigateTo'?
我在该行设置了一个断点,发现路由器没有方法navigateTo
。但是,它确实有方法navigate
。名称是否改变了?
define(['services/datacontext', 'plugins/router', 'services/logger'],
function (datacontext, router, logger) {
......
var gotoDetails = function (selectedEvent) {
if (selectedEvent && selectedEvent.Id()) {
var url = '#/eventdetail/' + selectedEvent.Id();
router.navigateTo(url);
}
};
var viewAttached = function (view) {
bindEventToList(view, '.event-brief', gotoDetails);
};
var bindEventToList = function (rootSelector, selector, callback, eventName) {
var eName = eventName || 'click';
$(rootSelector).on(eName, selector, function () {
var event = ko.dataFor(this);
callback(event);
return false;
});
};
//#endregion
var vm = {
activate: activate,
deactivate: deactivate,
refresh: refresh,
events: events,
title: title,
attached: viewAttached
};
return vm;
});
答案 0 :(得分:1)
您应该将申请转换为Durandal 2:
http://www.johnpapa.net/upgrading-durandal-to-version-2-0/ (除了其他更改之外,还有:router.navigateTo现在是router.navigate)
或使用官方Durandal 2模板代替HotTowel