我有一个json响应,我的Ember模型不适合它

时间:2014-12-02 07:32:01

标签: json ember.js ember-data

我的Json回复是这样的

   {
        "object": {
            "assignments": [
                {
                    "assignmentId": 14706368,
                    "sectionId": 0,
                    "assignmentType": "FILEATTACH",
                    "assignmentTitle": "file attachment A",
                    "assignmentStartDate": "01/01/1900",
                    "assignmentStartTime": "01:00AM",
                    "assignmentDueDate": "01/01/2100",
                    "assignmentDueTime": "01:00AM",
                    "isMarathonChain": "No",
                    "assignmentTimeLimit": 0,
                    "assignmentTimeRemaining": "0",
                    "marathonAssignmentStatus": "MARATHON_NOT_ASSOCIATED",
                    "showAssignmentAttemptsAndPasswordDetails": false,
                    "assignmentAttemptsTaken": 0,
                    "assignmentAttemptsAllowed": "1",
                    "showPasswordForm": false,
                    "isStartAssignment": true,
                    "isResumeAssignment": false,
                    "isSubmitAssignment": false,
                    "passwordRequired": false,
                    "isConvertToGeniusEnabled": false,
                    "draftNumber": 0,
                    "studentExceptionExistsForDueDate": false,
                    "isPastUploadDate": false,
                    "showMarathonPrerequisiteInfo": false
                }
            ],
            "sections": [
                {
                    "sectionId": 241409387,
                    "courseId": 241409386,
                    "sectionName": "Section01"
                }
            ],
            "courses": [
                {
                    "courseId": 241409386,
                    "courseName": "Tricon.Connect_01",
                    "showDiscipline": false
                }
            ],
            "users": [
                {
                    "userId": 1000321061,
                    "firstName": "Ragu �������&^&",
                    "lastName": "+#@)()XYZ �^^������",
                    "userType": "S"
                }
            ],
            "returnLMS": [
                {
                    "returnUrl": "bb"
                }
            ]
        }
    }

My data model is like this

var attr = DS.attr;
App.About = DS.Model.extend({
 object: DS.hasMany('object')
 });

App.Object = DS.Model.extend({
  assignments: DS.hasMany('assignments'),
  sections: DS.hasMany('sections'),
  courses: DS.hasMany('courses'),
  users:  DS.hasMany('users'),
  returnLMS: DS.hasMany('returnLMS')
});

App.Assignments = DS.Model.extend({
assignmentId: attr('number'),
sectionId:attr('number'),
assignmentType:attr('string'),
assignmentTitle:attr('string'),
assignmentStartDate:attr('string'),
assignmentStartTime:attr('string'),
assignmentDueDate:attr('string'),
assignmentDueTime:attr('string'),
isMarathonChain:attr('boolean'),
assignmentTimeLimit:attr('number'),
assignmentTimeRemaining:attr('number'),
marathonAssignmentStatus:attr('string'),
showAssignmentAttemptsAndPasswordDetails:attr('boolean'),
assignmentAttemptsTaken:attr('number'),
assignmentAttemptsAllowed:attr('number'),
showPasswordForm:attr('boolean'),
isStartAssignment:attr('boolean'),
isResumeAssignment:attr('boolean'),
isSubmitAssignment:attr('boolean'),
passwordRequired:attr('boolean'),
isConvertToGeniusEnabled:attr('boolean'),
draftNumber:attr('number'),
studentExceptionExistsForDueDate:attr('boolean'),
isPastUploadDate:attr('boolean'),
showMarathonPrerequisiteInfo:attr('boolean')
});

App.Sections = DS.Model.extend({
sectionId: attr('number'),
courseId: attr('number'),
sectionName: attr('string')

});

App.Courses = DS.Model.extend({
courseId: attr('number'),
courseName: attr('string'),
showDiscipline: attr('boolean')
});

App.Users = DS.Model.extend({
userId: attr('number'),
firstName: attr('string'),
lastName: attr('string'),
userType:attr('string')
});

App.ReturnLMS = DS.Model.extend({
returnUrl: attr('string')
});

在这个App.About中是我的路径名,所以我在其中创建了对象,其余部分如下所示。 不,我从restadapter得到我的回复,但不知何故,它与我的模型格式不匹配,我的模型对象显示为空。

1 个答案:

答案 0 :(得分:0)

看一下期待的JSON conventions Ember数据。

您还可以将模型输入到名为ember-data-model-maker的简洁工具中,并查看服务器响应应该是什么。

如果您无法控制服务器响应,则需要扩展DS.RESTAdapter以操纵您的JSON以使其进入Ember Data期望的格式。