干杯! 我有简单的行动:
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
}));
Set方法效果很好,但是当我尝试使用新的setted属性应用对象时,Ember给了我一个错误:
Uncaught TypeError: Cannot redefine property: __ember1360328485839
如何解决这个问题?
答案 0 :(得分:2)
尝试创建交易,将席位添加到交易中,修改席位,然后提交交易。
TravelClient.TourSeatsController = Ember.ObjectController.extend({
selectSeat: function(seat) {
var transaction = new App.store.transaction();
transaction.add(seat);
seat.set('free', false);
transaction.commit();
}
});