Ember.js EmberJS:允许在资源中使用可选ID
使用Emberjs,我希望遵循REST规范,即在未指定Ember.js EmberJS:允许在资源中使用可选ID,ember.js,ember-router,Ember.js,Ember Router,使用Emberjs,我希望遵循REST规范,即在未指定id时返回所有对象的数组: http://localhost:4200/database返回所有数据库(将是数据库) http://localhost:4200/database/:id返回所提供数据库的数据库信息(如预期) 我的路线定义如下: Router.map -> @resource "database", ":database_id", -> @route "new" @rou
id
时返回所有对象的数组:
返回所有数据库(将是http://localhost:4200/database
)数据库
返回所提供数据库的数据库信息(如预期)http://localhost:4200/database/:id
Router.map ->
@resource "database", ":database_id", ->
@route "new"
@route "edit"
我怎样才能在我的资源中允许一个可选的
id
?我不是CoffeeScript的忠实粉丝,所以我会用好的老JavaScript来回答
所以你的路线看起来是错误的,它们应该如下
App.Router.map(function() {
this.resource("databases", function() {
this.route("new"),
this.resource("databases", { path: '/databases/:id' }, function() {
this.route("edit"),
});
});
});
这将为您提供以下信息:
/databases (list of databases )
/databases/new ( create a new database )
/databases/:id ( view a database with id :id)
/databases/:id/edit (edit the database with id of :id )
这消除了需要可选ID的需要。使用这些路由,即使我显式调用我的路由
数据库
,Ember仍会向/数据库
发出请求。也许与此有关?思想?