javascript - 使用 id 以外的其他值

标签 javascript model ember.js ember-data

所以,对于 ember,它使用 id 来识别模型,它在 http 请求中也使用它

http://localhost/api/users/12

有没有办法使用不同的值作为它的 id?例如用户名?

结果是这样的......

http://localhost/api/users/john99

最佳答案

原来我不得不这样做

App.ApplicationSerializer = DS.RESTSerializer.extend({
  primaryKey: "username"
});

在尝试了很多不同的方法之后,这是唯一有效的方法。

关于javascript - 使用 id 以外的其他值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19792221/

相关文章:

javascript - Ember 计算升序排序

javascript - 将段落分成跨度

ruby-on-rails - Rails ActiveRecord 模型范围与 has_many 关联的连接

javascript - 更改 tumblr Spotify 嵌入

model - 错误传递模型 JAGS

php - 在 Laravel 中自定义模型存储的验证规则

javascript - 如何将复选框添加到 #{{link-to}} 帮助程序中

javascript - 在 Ember 模板中插入脚本标签

javascript - 在循环外访问循环内的所有变量

javascript - 如何使用 Javascript XMLHttpRequest 将 JSON 数据对象发送到服务器?