如何在Durandal路由器中使用splat参数? [英] How to use the splat parameter in Durandal router?
问题描述
我正在查看的文章是 Durandal Router 。
在 mapAuto
下,它表示可以在URL #/ customers / 1
。并且viewmodel中的 activate
函数将能够检索参数数组。
Under mapAuto
, it says we can pass splat parameter in the url #/customers/1
. and the activate
function in the viewmodel will be able to retrieve the parameter array.
我在这里建立了一条路线
I built a route here
router.mapRoute('view/:id', moduleId, 'Customer Details', false);
但是如何获取 id
激活
函数?文档页面上没有示例。请帮助我们。谢谢。
But how can I obtain the id
in the activate
function? There is no example on the doc page. Please help us out. Thank you.
推荐答案
为您的Activate函数提供一个参数,可能命名为 data。
Give your activate function a single parameter, perhaps named something like "data".
传递给网址的ID将在激活函数中作为 data.id提供。
The id that was passed into the url will then be available within the activate function as "data.id".
var activate = function(data) {
alert(data.id);
};
这篇关于如何在Durandal路由器中使用splat参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!