简体   繁体   English

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

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

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. 我需要Ember在尝试调用REST端点时停止尝试猜测,但是找不到解决方法。

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) 如果我有一个端点说/services ,我希望ember总是调用/services而不管我是在调用find('services')还是find('services', 1)

Same for singulars. 同样的单数。

Is it possible to disable this behavior? 是否可以禁用此行为? Even if I have to override methods in the REStAdapter that'd be OK. 即使我必须重写REStAdapter中的方法也可以。

Thanks! 谢谢!

Sure, but you still should use find('service'). 可以,但是您仍然应该使用find('service')。

Plural (this is the default implementation) 复数(这是默认实现)

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);
  },
});

Both Foo and Bar would be singular using the code below 使用以下代码,Foo和Bar都将是单数

App.FooAdapter = App.BaseSingularAdapter;

App.BarAdapter = App.BaseSingularAdapter;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据数组中的数据动态更改其宽度 - How to make dynamically change its width according to data from array 将单词的单数和复数视为一个 - Treat singular and plural of a word as one JavaScript中的多个和单个数组名称 - Plural and singular array names in JavaScript 使用Javascript的奇异VS多个单词? - Singular VS Plural Words with Javascript? 当某些字母发生变化时,如何在复数中找到单数? 最好的方法是什么? - How to find singular in the plural when some letters change? What is the best approach? 如何用for循环使数组中的字符串复数? - How to make strings in an array plural with a for loop? 为什么我的KendoUI图表会更改甚至没有连接的javascript变量中的日期格式? 以及如何使其停止? - Why is my KendoUI Chart changing the date format in a javascript variable it's not even connected to? And how to make it stop? JQuery验证对单/复数形式的支持 - JQuery validate support for singular/plural forms 根据可变长度使文本单数或复数 - Making text singular or plural based on variable length 为什么数据元素在 vuejs 中的某些 function 中没有改变其值以及如何使其值可变? - why the data element is not changing its value in some function in vuejs and how to make it's value changable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM