如何根据路由构建模型的自定义RESTAdapter?

时间:2015-08-22 21:31:28

标签: ember.js ember-data

我对Ember.js很新,所以仍然让基本面失灵。我有一个模型,我们称之为dog,其数据来自外部API。 API只允许您分别获得大型犬和小型犬:

http://api.example.com/big/dogs
http://api.example.com/small/dogs

如果我拥有自己的bigsmall路线 - 每条路线都会获得相应的狗列表 - 我该如何自定义DogAdapter' s buildURL方法根据当前路由汇总正确的API调用?

这是一个非常简单的例子,如果有任何需要澄清的话,请告诉我。

1 个答案:

答案 0 :(得分:0)

我明白了。例如,我的big路由应返回:

this.store.query( 'dog', { size: 'big' } )

我的DogAdapter应该定义如下内容:

buildUrl( model, id, snapshot, req, query ) {
    return 'http://api.example.com/' + query.size + '/dogs'
}