- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 drf 后端中有这个模型:
class Product:
price_range = ...
我正在将 EmberData 与 JSONApi 序列化器一起使用。我刚刚发现 JSON API 需要 dasherized 属性。所以我需要告诉 drf:
JSON_API_FORMAT_KEYS = 'dasherize'
该属性在 JSON
中序列化为:
price-range
然后,EmberData
开始跳舞,我得到了 Ember
模型属性:
import DS from 'ember-data';
export default DS.Model.extend({
...
priceRange: DS.attr('number'),
...
});
(旧的 RESTSerializer
期望 JSON
中的 priceRange
,如果我没记错的话)
所以,我们从 price_range
-> price-range
-> priceRange
(如果你问我的话,这相当疯狂)。我通过反复试验发现了这一切。对于 drf,相应的设置记录在 here 中.
JSONApi
、EmberData
和 Ember
的文档在哪里?我想确保我真的理解了这一点,而且人际关系也是如此。相关的 drf
配置设置为:
JSON_API_FORMAT_RELATION_KEYS = 'dasherize'
最佳答案
在 blog post for the Ember-Data 1.13
release Ember 数据团队写道:
JSONSerializer and RESTSerializer have been refactored and streamlined to return JSON API payloads.
这意味着 Ember Data 的发展需要与 JSON API 一致的短划线名称。请参阅the JSON API recommendation for dashes in between words of member names :
Member names SHOULD contain only the characters "a-z" (U+0061 to U+007A), "0-9" (U+0030 to U+0039), and the hyphen minus (U+002D HYPHEN-MINUS, "-") as separator between multiple words.
并查看 JSON API 主页上的一些示例 JSON:
-"attributes": {
"first-name": "Dan",
"last-name": "Gebhardt",
"twitter": "dgeb"
},
就型号而言,the most recent documentation for Ember 2.2.0状态:
In Ember Data the convention is to camelize attribute names on a model
使用多世界属性名称给出的示例模型符合预期:
export default DS.Model.extend({
firstName: DS.attr('string'),
lastName: DS.attr('string'),
isPersonOfTheYear: DS.attr('boolean')
});
虽然推荐的命名约定肯定发生了变化,但我预计此时大部分更改都已成为过去。核心团队已经注意到了。我相信围绕 JSON API 进行标准化的举措,以便可以构建可互操作和可重用的工具,但不幸的是,这一举措伴随着这些变化。
总之:在 JSON 中使用破折号名称,在模型中使用驼峰名称。
编辑:看起来,虽然 Ember Data 团队采用了有关 JSON 有效负载中的属性名称的 JSON API 建议,但这只是一个建议。请参阅 GitHub regarding the dasherized naming convention 上的讨论用于 JSON API。
关于ember.js - JSONAPI 的 Dasherize 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34546099/
我正在尝试将 ember-models 链接到 ember-table,以从服务器提取分页记录,并在向下滚动时将它们添加到表中。 我可以通过请求我的 api url 和页码来让它工作,就像 http:
我有一个应用程序,它使用 ember-data 来持久化数据和 StateManager 来驱动其全局状态。由于加载数据是异步的,我想知道如何捕获表示所有数据都已加载的事件。 准确地说,我有一个名为“
我有一个简单的 Ember 应用程序,其中有一个输入框、两个选择框和一个按钮。我可以在“doSearch”方法中访问输入框的值,但不能访问选择框的值。 到目前为止,我没有尝试任何工作 - 我注释掉了我
我使用 Ember-CLI 来构建我的 ember 应用程序,但我不想使用 Ember Data。 默认情况下,当你输入这个命令:ember generate model Person 时,ember
我按照 Ember CLI 主页的说明创建了我的第一个 Ember CLI 插件。该插件运行良好,并且已经在 Github 上获得了几颗星:https://github.com/lolmaus/emb
我在这里看到的以前的问题似乎都没有涵盖何时使用 Ember 计算属性与 Ember Observer 的主题。我知道计算属性使用以前的属性来帮助生成新属性并在运行循环中更新。 Person = Emb
我一直在 git 分支上切换到 1.13.2 版本的 ember,现在我想在返回另一个分支时回到 1.11.1。 我一直在运行npm install和 bower install没有失败。 但是当我运
我有一个使用 ember-cli 构建的 Ember 应用程序我正在使用 ember-qunit 编写我的测试使用 testem 测试适配器并在浏览器中运行它们按照 ember-cli 中的说明文档。
项目设置: Ember:2.0.0 Ember 数据:2.0.0 Ember-cli:1.13.8 我创建了一个转换:转换/isodate.js import DS from 'ember-data'
假设我有一个具有 2 个属性的组件:我如何能够基于 localID 属性和 Ember.compulated.filterBy 宏创建计算属性? localID: 2, data: [ { i
我刚刚创建了一个新的 Ember-CLI app (v0.1.12),并注意到 Ember 的引用版本是 v1.8.1 (bower.json)。我想要 recently released 1.10我
使用最新的 Ember (3.2)、ember-cli-mirage 0.4.7、ember-cli-qunit 4.3.2、ember-qunit 3.4.1 我正在使用 ember-cli-mir
我是一名 ember 菜鸟,正在阅读 ember-cli 101 这本书。迄今为止,我一直在 ember-cli 网站 here 上使用升级工作流程。 。 在终端中使用 ember-cli 帮助时,我
如何测试我的组件,将 ember-data 模型作为 props 传递给它? 例如: {{#queue/review/moderatable-text model=activity property=
Ember 对象和 Ember Data 中的对象有什么区别?我知道当服务器上有一些数据时我应该使用 Ember Data 模型,但是我应该何时何地使用它们中的任何一个? 最佳答案 注意:这很长,有偏
执行ember -v仅显示ember cli版本。 如何查看 ember.js 版本和 ember 数据版本? 最佳答案 ember.js 和 ember-data 的版本由应用的依赖项决定。 Bow
我正在尝试在 Ember.RSVP.all 内执行 promise App.Foo = Ember.Object.create({ bar: function() { var
访问 ember 对象属性的首选方法是什么?我经常看到 .get() 方法被使用,但想知道为什么人们不只是使用点表示法。例如在 Advice in the Use of Ember Trek 先生写道
我知道 Ember 有一个记录器,但我想创建自己的用于学习目的。我有一个名为 logger 的服务,我希望能够在任何地方使用这个服务。将此服务注入(inject)到组件、 Controller 等中没
我刚刚关注了 ember-cli 主页上的“入门”帖子。 我安装了 ember 0.1.2、bower、phantomjs 等。 但是,我创建了我的应用程序,当我运行“ember server”时,它
我是一名优秀的程序员,十分优秀!