ember.js在为其属性设置新值后应用对象 [英] ember.js apply object after setting new value for it's attribute

查看:79
本文介绍了ember.js在为其属性设置新值后应用对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

干杯!
简单的动作在这里我有:

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

我的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
  }));

设置方法运行良好,但是当我尝试使用新的setted属性应用对象时,Ember给了我一个错误:

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 

如何解决这个问题?

推荐答案

尝试创建一个事务,座位到交易,修改座位,然后提交交易。

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

这篇关于ember.js在为其属性设置新值后应用对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆