如果你想象两个模型定义如下:
App.User = DS.Model.extend({
emails: DS.hasMany('email', {embedded: 'always'}),
});
App.Email = DS.Model.extend({
address: DS.attr('string'),
alias: DS.attr('string'),
user: DS.belongsTo('user')
});
Run Code Online (Sandbox Code Playgroud)
...和REST适配器:
App.UserAdapter = DS.RESTAdapter.extend({
url: 'http://whatever.com',
namespace: 'api/v1'
});
Run Code Online (Sandbox Code Playgroud)
...路由设置如下:
App.Router.map(function () {
this.route('index', { path: '/' });
this.resource('users', function () {
this.route('index');
this.route('add');
this.resource('user', { path: ':user_id' }, function () {
this.route('delete');
this.route('edit');
this.resource('emails', function () {
this.route('index');
this.route('add');
this.resource('email', { path: ':email_id' }, function () {
this.route('delete');
this.route('edit');
});
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
...以及用于保存已编辑电子邮件的控制器操作,如下所示:
App.EmailEditController = Ember.ObjectController.extend({
actions: { …Run Code Online (Sandbox Code Playgroud)