【发布时间】:2014-08-14 10:15:59
【问题描述】:
任何人都可以解决这个我已经挣扎了几个小时的问题,这将是很棒的......
我是 ember.js 的新手,我正在尝试通过以下方式将用户模型加载到我的应用程序的全局范围中:
(安装程序基于this template 并从那里使用 webapi_adapter 和序列化程序。)
据我所知,我需要使用以下内容:
ApplicationController.js
App.ApplicationController = Em.ObjectController.extend({
hasError: function () {
var currentError = this.get("error");
return !(currentError === '' || currentError === null);
}.property('error'),
});
User.js
var attr = DS.attr;
App.User = DS.Model.extend({
email: attr('string'),
accountId: attr('string'),
firstName: attr('string'),
lastName: attr('string'),
});
App.UserSerializer = DS.WebAPISerializer.extend({
primaryKey: 'email',
normalizeHash: {
user: function (hash) {
hash.email = hash.email;
return hash;
},
}
});
ApplicationRoute.js
App.ApplicationRoute = Ember.Route.extend({
model: function() {
return this.store.find('user');
},
});
UserController.cs
//GET api/user
public object GetCurrentUser()
{
var u = AuthenticatedUser;
return new UserDto(u);
}
UserDto.cs
public class UserDto
{
public UserDto() { }
public UserDto(User user)
{
Email = user.Email;
FirstName = user.FirstName;
LastName = user.LastName;
AccountId = user.AccountId;
}
[Key]
public string Email { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string AccountId { get; set; }
}
我遇到的问题是我得到了错误
Error while processing route: index No model was found for 'email' Error: No model was found for 'email'
其中 email 是用户数据中返回的第一个 json 属性,即:
{"Email":"johnsmith@test.com","FirstName":"John","LastName":"Smith","AccountId":"AccountJS"}
任何想法我做错了什么?
仅供参考:
router.js
App.Router.map(function () {
this.route("index", { path: "/" });
});
【问题讨论】:
标签: c# javascript asp.net ember.js asp.net-web-api