1
google搜索的时候,我看到很多的例子是这样的:用正则表达式骨干路由器和扩展
App.Router = Backbone.Router.extend({
routes: {
'': 'index',
'show/:id': 'show'
},
index: function(){
$(document.body).append("Index route has been called..");
},
show: function(id){
$(document.body).append("Show route with id: " id);
}
});
这将如何实现像使用正则表达式?
我想是这样的:
App.Router = Backbone.Router.extend({
routes: {
'': 'index',
/show/(\d+:id)/: 'show'
/show/([A-Za-z]+:other)/: 'showSpecial'
},
其中第一个正则表达式匹配/show/[any number]
并将在id
参数的show
功能号码。
以及第二个正则表达式匹配/show/[any word]
并将other
参数中的单词传递给showSpecial
函数。
检查这一项[骨干路由的正则表达式(HTTP://计算器。 COM /问题/ 18061925 /骨干路由正则表达式) –