【问题标题】:Find the list of defined sammy.js routes查找已定义的 sammy.js 路由列表
【发布时间】:2010-10-07 13:15:09
【问题描述】:

Sammy.js 是 javascript 中的控制器库。但有时我们有 404,因为我们的路线似乎对 sammy 无效。

如何知道页面中 Sammy.js 定义了哪些路由?

类似于 ruby​​ on rails 的rake routes

我们可以在 app.routes 上搜索答案。所以我在咖啡脚本中有类似的东西:

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

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

但它并没有输出我在输出中的好路线:

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

那么该做哪些代码呢?

【问题讨论】:

  • 路线是我说的! ;)(我不知道我几乎是一个控制器库;))
  • 是的,在此之前没有关于这个库的答案。所以我链接它有问题

标签: javascript routes sammy.js


【解决方案1】:

你可以试试这样的

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

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

【讨论】:

    【解决方案2】:

    RTC:路由被添加到app.routes,只需编写一个访问器返回一个迭代器。

    【讨论】:

    • 你说得对,但是这样更复杂,因为路由是一个带有键动词和值 URL 的哈希
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-24
    • 2020-08-16
    • 2012-12-18
    • 2017-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多