简体   繁体   中英

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:

      {{#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:

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();
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM