我需要Ember在尝试调用REST端点时停止尝试猜测事情,但是找不到做到这一点的方法。

如果我有一个端点说/services,那么我希望ember总是调用/services,而不管我是在调用find('services')还是find('services', 1)
相同的单数。

是否可以禁用此行为?即使我必须重写REStAdapter中的方法也可以。

谢谢!

最佳答案

可以,但是您仍然应该使用find('service')。

复数(这是默认实现)

App.ServiceAdapter = DS.RESTAdapter.extend({
  pathForType: function(type) {
    var camelized = Ember.String.camelize(type);
    return Ember.String.pluralize(camelized);
  },
});

单数
App.ServiceAdapter = DS.RESTAdapter.extend({
  pathForType: function(type) {
    var camelized = Ember.String.camelize(type);
    return camelized; //Ember.String.pluralize(camelized);
  },
});

基奇异类
App.BaseSingularAdapter = DS.RESTAdapter.extend({
  pathForType: function(type) {
    var camelized = Ember.String.camelize(type);
    return camelized; //Ember.String.pluralize(camelized);
  },
});

使用以下代码,Foo和Bar都将是单数
App.FooAdapter = App.BaseSingularAdapter;

App.BarAdapter = App.BaseSingularAdapter;

10-07 20:01
查看更多