[英]ember.js apply object after setting new value for it's attribute
Cheers! 干杯! Simple action here I have: 我有简单的行动:
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'));
}
});
my html: 我的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>
...............................................................................
Object's structure: 对象的结构:
...addObject(TravelClient.Seat.create({
id: i,
free: true
}));
Set method works well, but when I trying to apply object with new setted property, Ember gives me an error: Set方法效果很好,但是当我尝试使用新的setted属性应用对象时,Ember给了我一个错误:
Uncaught TypeError: Cannot redefine property: __ember1360328485839
How to fix this? 如何解决这个问题?
Try creating a transaction, add the seat to the transaction, modify the seat, then commit the transaction. 尝试创建交易,将席位添加到交易,修改席位,然后提交交易。
TravelClient.TourSeatsController = Ember.ObjectController.extend({
selectSeat: function(seat) {
var transaction = new App.store.transaction();
transaction.add(seat);
seat.set('free', false);
transaction.commit();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.