干杯!
我这里的简单动作:
TravelClient.TourSeatsController = Ember.ObjectController.extend({
selectSeat: function(seat) {
// console.log(seat.get('id'));
// console.log(seat.get('free'));
seat.set('free', false);
TravelClient.Seat.apply(seat);
// console.log(seat.get('free'));
}
});
我的html:
{{#each seat in controller.seatsArray}}
<li class="item">
{{#if seat.free}}
<div class="counter-value">
<a href="#" {{action "selectSeat" seat}}>{{seat.id}}</a>
</div>
...............................................................................
对象的结构:
...addObject(TravelClient.Seat.create({
id: i,
free: true
}));
设置方法效果很好,但是当我尝试应用具有新设置属性的对象时,Ember给了我一个错误:
Uncaught TypeError: Cannot redefine property: __ember1360328485839
如何解决?
最佳答案
尝试创建事务,将席位添加到事务中,修改席位,然后提交事务。
TravelClient.TourSeatsController = Ember.ObjectController.extend({
selectSeat: function(seat) {
var transaction = new App.store.transaction();
transaction.add(seat);
seat.set('free', false);
transaction.commit();
}
});