[英]Find the list of defined sammy.js routes
Sammy.js是javascript中的控制器库。 但是有时候我们有一个404,因为我们的路线似乎对萨米人无效。
如何知道Sammy.js在页面中定义的路由?
像在轨道上红宝石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...
那要做什么代码呢?
RTC:将路由添加到app.routes ,只需编写一个访问器即可在其上返回迭代器。
你可以尝试这样的事情
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.