简体   繁体   English

查找已定义的sammy.js路由列表

[英]Find the list of defined sammy.js routes

Sammy.js is a controller library in javascript. Sammy.js是javascript中的控制器库。 But sometimes we have a 404 because our route doesn't seems to be valid to sammy. 但是有时候我们有一个404,因为我们的路线似乎对萨米人无效。

How to know which route are defined by Sammy.js in a page ? 如何知道Sammy.js在页面中定义的路由?

Something like the ruby on rails' rake routes . 像在轨道上红宝石rake routes

Like answers we can search on app.routes. 像答案一样,我们可以在app.routes上进行搜索。 So I have something like in coffee script : 所以我在咖啡脚本中有一些类似的东西:

jQuery.each app.routes, (r) ->
  console.log(JSON.stringify(r))
  jQuery.each app.routes[r], (u) ->
    console.log(JSON.stringify(u))

or in JS 或在JS中

jQuery.each(app.routes, function(r) {
  console.log(JSON.stringify(r));
  return jQuery.each(app.routes[r], function(u) {
    return console.log(JSON.stringify(u));
  });
});

But it's not output the good routes I have in output : 但这并没有输出我在输出中拥有的好的路线:

"get"
0
1
"post"
0
1
2
etc...

So which code to do ? 那要做什么代码呢?

RTC:将路由添加到app.routes ,只需编写一个访问器即可在其上返回迭代器。

You can try something like that 你可以尝试这样的事情

var app = $.sammy.apps['body'];

jQuery.each(app.routes, function(verb, routes) {
  jQuery.each(routes, function(i, route) {
    console.log(route.verb, route.path);
  });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM