2014-12-02 117 views
0

我有我的控制器和模型。我試圖訪問模式控制器內部這樣 App.AssignmentController = Ember.ArrayController.extend({無法訪問控制器內的Ember模型數據

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/61/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'), 
}); 

我現在想訪問此控制器內這種模式,但我無法訪問它。這裏,在這個控制器我將操縱一些額外的條件,並使用這在我的模板檢查一些條件。

回答

0

model鉤需要一個promiseobjectarray要返回(您省略了return語句)。

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

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

+0

我也這樣做,但現在還我沒有得到從我的控制器的任何事情。它返回undefined。還有一件事我注意到,通過在該控制器中放置調試點,當它來到該控制器時,我的模型未設置,並且一旦我按下F8並從中出來,我的模型將設置爲所有值。這可能是一個問題嗎? – 2014-12-03 07:23:12

相關問題