无法访问控制器内的Ember模型数据

时间:2014-12-02 15:26:50

标签: ember.js ember-data

我有我的控制器和型号。我试图像这样访问控制器内的模型 App.AssignmentController = Ember.ArrayController.extend({

    App = Ember.Application.create({});


App.Router.map(function() {
  this.resource('assignment',{path:'about'});
});


App.AssignmentAdapter = DS.RESTAdapter.extend({


    findQuery: function(store, type, queryData) {

         var findQueryURL = 'http://local_env.mhhe.com/openapi/lms/coversheet/sectionid/241409387/assignmentid/14706368/userid/1000321061/isangelinstallation/false/returnUrl/bb';
         return this.ajax(findQueryURL, 'POST', {
            data: queryData.query
         })
    }

});

App.AssignmentRoute = Ember.Route.extend({
  model: function() {
    return this.store.findQuery('assignment','1');
  },
});
  var attr = DS.attr;

App.Assignment = 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.AssignmentController = Ember.ArrayController.extend({

    displayAssignments: function(){
        var assignments = this.get('model.assignment');
       // i also tried this.store.find but that also didnt gave me the output 
        return assignments;

    }.property('model.assignment'),
});

现在我正在尝试在此控制器内访问此模型,但我无法访问它。在这个控制器中,我将操纵一些额外的条件,并在我的模板中使用它来检查一些条件。

1 个答案:

答案 0 :(得分:0)

您的model钩子需要返回promiseobjectarray(您省略了return声明。)

model: function() {
  return this.store.findQuery('assignment','1');
}

http://emberjs.com/guides/routing/specifying-a-routes-model/