简体   繁体   中英

Find the list of defined sammy.js routes

Sammy.js is a controller library in javascript. But sometimes we have a 404 because our route doesn't seems to be valid to sammy.

How to know which route are defined by Sammy.js in a page ?

Something like the ruby on rails' rake routes .

Like answers we can search on 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

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);
  });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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