在Ember.js中查找记录不起作用

在Ember.js中查找记录不起作用,ember.js,Ember.js,我的代码: App = Ember.Application.create(); App.ApplicationAdapter = DS.FixtureAdapter.extend(); App.Student=DS.Model.extend({ name:DS.attr('string'), projects:DS.hasMany('project',{async:true}) }); App.Project=DS.Model.extend({ name:DS.attr('st

我的代码:

App = Ember.Application.create();

App.ApplicationAdapter = DS.FixtureAdapter.extend();

App.Student=DS.Model.extend({
  name:DS.attr('string'),
  projects:DS.hasMany('project',{async:true})
});

App.Project=DS.Model.extend({
  name:DS.attr('string'),
  student:DS.belongsTo('student')
});

App.Student.FIXTURES = [
 { id: 1, name: 'Kris', projects: [1,2] },
 { id: 2, name: 'Luke', projects: [3] }
];

App.Project.FIXTURES=[
 { id:1,name:'Proj1',student:1 },
 { id:2,name:'Proj2',student:1},
 { id:3,name:'Proj3',student:2}
]; 

App.IndexRoute = Ember.Route.extend({
 model: function() {   
   return this.store.find('student');
 }
});

App.IndexController=Ember.ArrayController.extend({
  actions:{
    saveRecord:function(){
    var stu1=this.store.find('student',1);
    console.log(stu1.get('name'));  // RETURNS Undefined
  }
 }
});

在IndexController中,按id查找记录不起作用。它的返回未定义。我的代码怎么了?

您必须在find语句中使用承诺:

this.store.find('student', 1).then(function(stu1) {
   // success
   console.log(stu1.get('name'));
}, function(error) {
   // error handling
   console.log(error);
});