Javascript 如何基于off-id在主干网中建立路由
我正在尝试使用主干线为水疗中心设置路线。我想做的是在url中输入一个用户类型,例如http://…./image\u sets/1,然后执行GET请求,从API数据库返回id为1的图像集。我似乎不知道如何将用户在url中输入的id传递给GET请求。我还想知道我是否正确设置了路线,以便显示各个图像集?谢谢Javascript 如何基于off-id在主干网中建立路由,javascript,jquery,ajax,backbone.js,Javascript,Jquery,Ajax,Backbone.js,我正在尝试使用主干线为水疗中心设置路线。我想做的是在url中输入一个用户类型,例如http://…./image\u sets/1,然后执行GET请求,从API数据库返回id为1的图像集。我似乎不知道如何将用户在url中输入的id传递给GET请求。我还想知道我是否正确设置了路线,以便显示各个图像集?谢谢 var Router = Backbone.Router.extend({ routes: { '': 'home', 'users': 'users',
var Router = Backbone.Router.extend({
routes: {
'': 'home',
'users': 'users', // users does not exist
'images': 'images',
'comments': 'comments',
'likes': 'likes',
'postImages': 'postImages',
'image_sets/:id' : 'image_sets'
},
image_sets: function(id) {
$('#content').empty();
$('#myCarousel').hide();
$.ajax({
url: 'https://pixelect-rails-api.herokuapp.com/image_sets/id',
type: 'GET'
}).done(function(response) {
console.log(response);
var template = Handlebars.compile($('#imageSetsTemplate').html());
$('#content').html(template({
image_set: response
}));
});
},
将id连接到URL字符串:URL:'https://pixelect-rails-api.herokuapp.com/image_sets/“+id,谢谢,这很有效,尽管现在我得到了一个错误“uncaughterror:您必须将字符串或handlebar AST传递给handlebar.compile”。您在“var template=handlebar.compile$'imageSetsTemplate.html;”行上传递了未定义的有什么想法吗?有两件事是可能的。元素不存在->重复检查。或者,DOM还没有准备好。在这种情况下,将所有内容包装在$function{}中;我发现了,模板id有一个输入错误,谢谢你的帮助。