this.id は Blog.Collections.Posts クラスでは未定義です。どうしたの?
ブログ集
Blog.Collections.Posts = Backbone.Collection.extend({
model: Blog.Models.Post,
url: function() {
console.log(this.id);
if (this.id) {
return '/api/posts/'+this.id
}
else{
return '/api/posts'
}
}
});
私のルーター:
Blog.Routers.Posts = Backbone.Router.extend({
routes: {
"" : "index",
"entry/:id" : "show"
},
show: function(id) {
var collection = new Blog.Collections.Posts({id: id});
collection.fetch({
success: function() {
var view = new Blog.Views.PostsIndex({ collection: collection });
console.log(collection);
}
});
}
});