本文介绍了如何使Ember数据根据其规则停止将端点更改为单数和复数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need Ember to stop trying to guess things when making calls to the REST endpoints, but can't find a way do do so.

如果我有端点说, / services ,我希望ember始终调用 / services ,无论我打电话给 find('services') find('services',1)

If I have an endpoint say, /services, I want ember to always call /services regardless if I'm making a call to find('services') or find('services', 1)

与单数相同。

是否可以禁用此行为?即使我必须覆盖REStAdapter中的方法,这样就可以了。

Is it possible to disable this behavior? Even if I have to override methods in the REStAdapter that'd be OK.

谢谢!

推荐答案

当然,但您仍然应该使用find('service')。

Sure, but you still should use find('service').

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



单数



Singular

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



基本单一类



Base Singular Class

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

使用下面的代码,Foo和Bar都将是单一的

Both Foo and Bar would be singular using the code below

App.FooAdapter = App.BaseSingularAdapter;

App.BarAdapter = App.BaseSingularAdapter;

这篇关于如何使Ember数据根据其规则停止将端点更改为单数和复数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 17:03