2

So, with ember it uses the id's a lot to identify models, it uses it in http request's as well like

http://localhost/api/users/12

Is there any way to use a different value as it's id? like a username for example?

so it ends up like this...

http://localhost/api/users/john99

4

3 回答 3

1

Turns out i had to do this

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

After trying a lot of different ways, this is the only one that worked.

于 2013-11-05T16:24:57.317 回答
0

you can use Route in Ember to tell what you wanna use something like:

App.UsersitemRoute = Ember.Route.extend({
  serialize: function(model, params) {
    return { username: model.get('username') };
  }
});

in your UserModel you need to do something like:

App.Usersitem = DS.Model.extend({
    username: DS.attr('string'),
});
于 2013-11-05T15:20:10.713 回答
0

This method is called when transitionTo is called with a context in order to populate the URL.

于 2013-11-05T16:29:39.703 回答