如何在Durandal路由器中使用splat参数? [英] How to use the splat parameter in Durandal router?

查看:56
本文介绍了如何在Durandal路由器中使用splat参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看的文章是 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆