如何使Ember数据停止根据其规则更改我的端点为单数和复数

How to make Ember data stop changing my endpoints to singular and plural according to its rules?

本文关键字:端点 我的 单数 规则 数据 Ember 何使      更新时间:2023-09-26

我需要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;