在EmberJS中是否支持单字母字体模型? [英] Are single-lettered word models supported in EmberJS?

查看:88
本文介绍了在EmberJS中是否支持单字母字体模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法确切地确定问题是否与Ember或Ember数据有关,或者甚至是一个问题,但是会发生什么:

I cannot really pinpoint whether the issue is with Ember or Ember data, or if it's even an issue, but here's what happens:

您的模型称为 tell_me_a_story 。如果您使用ActiveModelAdapter,那么这将是您的JSON应该提供的名称。

Let's say you've got your model called tell_me_a_story. This will be the name that your JSON should provide, should you be using ActiveModelAdapter.

无论如何,当Ember或Ember Data在内部进行处理时,成为 tellMeAStory ,正确地表示A和故事是两个单独的单词。

Regardless, when Ember or Ember Data process it internally, it'll camelize it and it becomes tellMeAStory, correctly indicating that "A" and "Story" are two separate words.

然而,当内部它是为了查找模型而进行的,它的重新包装功能会将它转换成 tell_me_astory

However, when internally it is decamelized to lookup for the model, the decamelize function will convert it into tell_me_astory.

对我来说有缺陷,但是当看到导出这种行为的测试时,实际上是以这种方式来管理首字母缩略词。 (比较下面的例子与我想要的骆驼套多字母首字母缩略词的innerHtml)。

This final behavior seems flawed to me, but when looking at the tests that derived this behavior, it is actually intended to manage acronyms in that fashion. (Compare the following example with the "innerHtml" that I would expect for camel casing multi-letter acronyms.)

QUnit.test("converts a camelized string into all lower case separated by underscores.", function() {
  deepEqual(decamelize('innerHTML'), 'inner_html');
  if (Ember.EXTEND_PROTOTYPES) {
    deepEqual('innerHTML'.decamelize(), 'inner_html');
  }
});

Ember Runtime中的源

所以,在Ember模型中使用单字母单词的正确方法是什么?他们是否支持?

以下是我要做的一个例子:

Here's an example of what I'm trying to do:

// this comes from a separate data source, e.g. REST APIs
var myModelName = 'tell_me_a_story';
// this line will throw if the model file is named "tell-me-a-story"
if (!store.getById(myModelName, 1)) {
  // this line will throw if the model file is named "tell-me-astory"
  store.pushPayload(myModelName, myObject);
}


推荐答案

a href =https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/store.js#L1950 =nofollow> _normalizeTypeKey 然后更改camelCase行为成为您想要的(例如,dasherized或只是修复这种情况)。

You can override the stores _normalizeTypeKey then alter the camelCase behaviour to become what you want (e.g. dasherized or just fix this one case).

您也可以覆盖序列号 typeForRoot 当这种方式 - 这可以告诉我们模型键是什么(例如 tellMeAStory )for a您的数据中的特定键(例如 tell_me_a_story )。

You can also override the serialisers typeForRoot when going the other way - this lets you tell ember what the model key is (e.g. tellMeAStory) for a particular key in your data (e.g. tell_me_a_story).

似乎有一些工作正在进行中,使一切工作都像容器确实(这是dasherized)

It appears there is work underway to make everything work like the container does (which is dasherized)

这篇关于在EmberJS中是否支持单字母字体模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆