我基本上按照你的描述做。我使用下面的代码调用后端以获取当前登录的用户并将其设置在 Ember 应用程序中。
var App = Ember.Application.create({
LOG_TRANSITIONS: true,
});
App.deferReadiness();
$.ajax({
url: 'http://localhost:3000/login',
dataType: 'json',
success: function (resp) {
console.log(resp.user);
App.store.load(App.User, resp.user._id, resp.user);
App.store.load(App.Company, resp.company._id, resp.company);
var user = App.User.find(resp.user._id);
var company = App.Company.find(resp.company._id);
App.CurrentUserController.reopen({
content: user
});
App.CurrentCompanyController.reopen({
content: company
});
App.advanceReadiness();
},
error: function (resp) {
console.log('failed: ' + resp);
App.advanceReadiness();
}
});
App.initialize();