gpt4 book ai didi

javascript - Backbone.js 路由器 url 包含参数

转载 作者:行者123 更新时间:2023-11-30 18:07:24 25 4
gpt4 key购买 nike

如果 url 某处包含具有指定操作的参数,我如何匹配路由?像 myaction/someparam1/someparam2/PleaseMatchMeIfYourFindMe/someparam3

最佳答案

主干 routes objects不提供相当程度的灵 active 。但是,您可以使用 route method 手动添加路由正则表达式:

route router.route(route, name, [callback])

Manually create a route for the router, The route argument may be a routing string or regular expression.

所以你可以在你的路由器中做这样的事情:

initialize: function() {
this.route(/^myaction\/.*PleaseMatchMeIfYourFindMe/, 'handler_method');
}

当然,您必须调整正则表达式以符合您的实际要求。如果您想获取部分正则表达式作为处理程序的参数,请根据需要添加捕获组。

演示:http://jsfiddle.net/ambiguous/pFXr6/

关于javascript - Backbone.js 路由器 url 包含参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15492027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com