EmberJS 是否支持单字母单词模型?

Are single-lettered word models supported in EmberJS?

我无法真正确定问题是出在 Ember 还是 Ember 数据上,或者它是否是一个问题,但这是发生了什么:

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

无论如何,当Ember或Ember数据在内部处理时,它会将其驼峰化并变为tellMeAStory,正确地表明"A"和"Story" 是两个单独的词。

但是,当在内部对模型进行 decamelized 查找时,decamelize 函数会将其转换为 tell_me_astory.

这种最终行为对我来说似乎是有缺陷的,但在查看派生这种行为的测试时,它实际上是为了以这种方式管理首字母缩略词。 (将以下示例与我期望的驼峰式多字母首字母缩略词 "innerHtml" 进行比较。)

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

(Source in Ember Runtime)

那么,在 Ember 模型中使用单字母单词的正确方法是什么?他们甚至支持吗?


这是我正在尝试做的一个例子:

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

您可以覆盖商店 _normalizeTypeKey 然后改变驼峰式行为以成为您想要的(例如破折号或只修复这一种情况)。

你也可以覆盖序列化程序 typeForRoot 当你走另一条路时 - 这让你告诉 ember 模型密钥是什么(例如 tellMeAStory)对于你的特定密钥数据(例如 tell_me_a_story)。

似乎正在进行使一切都像容器一样工作的工作(虚线化)