代码有什么问题?预期结果:当页面加载如url / case#!open-cases或url / cases#!new时,目标路由列表器(' new route'或者#39;:filter-cases route' ;)应该被调用,但它不会发生
PageControl = can.Control({
init : function(el, options) {
debugger;
},
'new route': function() {debugger;},
':filter-cases route': function() {debugger;
new CaseList('#content');
},
'route': function(data) {debugger;
new CaseList('#content');
}
});
$(document).ready(function() {
//initDialog();
can.route(':filter-cases');
can.route('case/:id');
can.route('new');
//can.route('', {filter: 'open' })
can.route.ready();
new PageControl(window);
});
答案 0 :(得分:1)
如果您在初始化页面控件后调用can.route.ready()
,它应该有效:
$(document).ready(function() {
//initDialog();
can.route(':filter-cases');
can.route('case/:id');
can.route('new');
//can.route('', {filter: 'open' })
new PageControl(window);
can.route.ready();
});