具有多个参数的骨干路由器 [英] Backbone router with multiple parameters
本文介绍了具有多个参数的骨干路由器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要让它工作:
routes: {
':product' : 'showProduct',
':product/:detail': 'showProductDetail'
showProductDetail永远不会被调用':product'路线即使在之后设定也会设定。我尝试了以下
showProductDetail never gets called while the ':product' route is set even if it is set afterwards. I tried the following
routes: {
':product(/:detail)': showProductOrDetail
}
但只有第二个参数发生变化时才会调用此方法。
我必须拥有产品本身或网址中的产品和详细信息。
But this will not get called when only the second parameter changes. It is important that I have the product itself or the product and detail in the url.
有谁知道如何修复这个?
Does anyone know how to fix this?
推荐答案
对你的问题有一些小问题。我有一种感觉,有一种更好的方法可以做到这一点,但这应该有效:
There's a little hacky solution to your problem. I have a feeling there is a nicer way to do this but that should work:
routes: {
"product/:id": "showProduct",
"product/:id/details/:did": "showDetails"
},
showProduct: function(id) {
this.showDetails(id);
},
showDetails: function(id, did) {
// Check did for undefined
}
这篇关于具有多个参数的骨干路由器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文