2015-01-13 1 views
1

Imberjs를 배우는 중이며 버튼을 누를 때 불리언 값을 변경하는 데 어려움이 있습니다.내 코드가 emberjs의 값을 변경하지 않는 이유는 무엇입니까?

이것은 내가 자바 스크립트에서 무엇을하고 무엇을 :

App.LiensController = Ember.ArrayController.extend({ 
    actions: { 
    addToPortfolio: function() { 
     this.set('isInPortfolio', true); 
     console.log('Action is Happening!'); 
    } 
    } 
}); 

App.LIENS=[ 
    { 
      id: 1, 
      apn: 'apn1', 
      fips: '01700', 
      state: 'CA', 
      county: 'Los Angeles', 
      address: 'somewhere st123', 
      debt: 4000, 
      isBiddedOn: false, //check 
      isInPortfolio: false 
    }, 
    { 
      id: 2, 
      apn: 'apn2', 
      fips: '01744', 
      state: 'FL', 
      county: 'Miami', 
      address: 'someplace st700', 
      debt: 2000, 
      isBiddedOn: false, //check 
      isInPortfolio: true   
    }, 
    { 
      id: 3, 
      apn: 'apn3', 
      fips: '05690', 
      state: 'FL', 
      county: 'Orlando', 
      address: 'ExactPlace in st111', 
      debt: 2500, 
      isBiddedOn: false, //check 
      isInPortfolio: false 
    } 
]; 

나는 또한 this.toggleProperty('isInProperty');을 사용하려고하지만 그것이 나도 작동하지 않습니다. 내가 잘못 뭐하는 거지

<script type="text/x-handlebars" data-template-name="liens"> 

    <h2 class="sub-header" >Liens</h2> 
     <div class="table-responsive"> 
     <table class="table table-hover"> 
      <thead> 
      <tr> 
       <th>id</th> 
       <th>apn</th> 
       <th>fips code</th> 
       <th>State</th> 
       <th>County</th> 
       <th>Address</th> 
       <th>Debt</th> 
       <th>Current Bid</th> 
       <th>IsInPortfolio</th> 
      </tr> 
      <tbody> 
      {{#each lien in model}} 
      <tr> 
       <td>{{lien.id}}</td> 
       <td>{{lien.apn}}</td> 
       <td>{{lien.fips}}</td> 
       <td>{{lien.state}}</td> 
       <td>{{lien.county}}</td> 
       <td>{{lien.address}}</td> 
       <td>${{lien.debt}}</td> 
       <td>{{lien.isBiddedOn}}</td> <!--Check--> 
       <td>{{lien.isInPortfolio}}</td> 
       <td><button id='addLien' type='button' {{action 'addToPortfolio'}}>Add</button></td> 
      </tr> 
      {{/each}} 
      </thead> 
    </script> 

:

그리고이 버튼이있는 HTML 부분은 무엇입니까? 여기에 은 jsbin입니다. http://emberjs.jsbin.com/fisifu/8/edit?html,js,output

미리 감사드립니다.

답변

2

귀하는 #each 도우미의 유치권 목록을 반복하고 있지만 개별 유치권의 속성을 변경하려고합니다.

App.LiensController = Ember.ArrayController.extend({ 
// actions: { 
//  addToPortfolio: function() { 
//  this.set('isInPortfolio', true); 
//  console.log('Action is Happening!'); 
//  } 
// } 
}); 

App.LienController = Ember.ObjectController.extend({ 
    actions: { 
    addToPortfolio: function() { 
     this.set('isInPortfolio', true); 
     console.log('Action is Happening!'); 
    } 
    } 
}); 
: 당신은 실제로 당신이 LienControllerLiensController에 있었다 논리를 선취 특권 컨트롤러를 만들어 둘 필요가 그런

{{#each lien in model itemController='lien'}} 

: 당신과 같이 개별 담보권의 controller를 지정하는 itemController를 사용할 필요가

작업은 itemControllerhere

,691에

here 데모

+0

니스, 그래서 매번 각 도우미 내의 개별 항목을 변경하려면 itemController를 사용해야합니까? 이것을 사용하지 않는 방법이 있습니까? – FutoRicky

+1

Ember 2.x가 itemController를 제거하려고 시도하고 있습니다. 다음 토론 참조 http://discuss.emberjs.com/t/what-is-a-good-way-to-do-this-in-ember-2- 0-itemcontroller-no-arraycontroller/6649입니다. 어느 쪽이든, 당신은 귀하의 경우에 개별 lien과 itemController의 상태를 추적 할 수있는 방법이 필요합니다. – Kalman

관련 문제