Ember.js从控制器获取数据

时间:2013-02-15 16:00:42

标签: javascript ember.js

我有一个控制器,我在其中定义TakenSeatNumbers变量:

TravelClient.TourSeatsController = Ember.ObjectController.extend({
  selectSeat: function(seat) {
    var orderTransaction = TravelClient.store.transaction();
    var takenSeatNumber = orderTransaction.createRecord(TravelClient.TakenSeatNumber, {number: seat.get('id')});
  }
});

如何从TakenSeatsNumbers模板访问tour/seats?模型Tour位于TourSeatsController

的上下文中

1 个答案:

答案 0 :(得分:1)

根据我的评论,将该函数变量(takenSeatsNumber)提升为控制器内的属性,使其公开,类似于以下内容:

TravelClient.TourSeatsController = Ember.ObjectController.extend({
  takenSeatNumber: null, 
  selectSeat: function(seat) {
    var orderTransaction = TravelClient.store.transaction();
    this.set('takenSeatNumber', 
             orderTransaction.createRecord(TravelClient.TakenSeatNumber, {number: seat.get('id')})
    );
  }
});