2013-10-01 4 views
1

열 B의 선택을 변경하면 열 A의 텍스트도 변경해야하지만 변경되지는 않습니다. 왜?테이블의 녹아웃 업데이트 셀 값

HTML :

<table> 
    <thead> 
     <tr> 
      <th style="width: 100px;">A</th> 
      <th style="width: 100px;">B</th> 
     </tr> 
    </thead> 
    <tbody data-bind="foreach: Data"> 
     <tr> 
      <td><span data-bind="text: idOpt"></span></td> 
      <td><select data-bind="options: $root.MyOptions, optionsText: 'name', optionsValue: 'id', value: idOpt"></select></td> 
     </tr> 
    </tbody> 
</table> 

JS :

function AppViewModel() { 
    var self = this; 
    self.MyOptions = ko.observableArray([ 
     {id: 'a1', name: 'One'}, 
     {id: 'a2', name: 'Two'}, 
     {id: 'a3', name: 'Three'} 
    ]); 

    self.Data = ko.observableArray([ 
     {idOpt: 'a1'}, 
     {idOpt: 'a2'}, 
     {idOpt: 'a1'} 
    ]); 
} 

var vm = new AppViewModel(); 
ko.applyBindings(vm); 

http://jsfiddle.net/bnowicki/CrVBr/2/

이 도와주세요.

답변

2

바인딩/업데이트하려는 경우 데이터 배열의 항목을 관찰 가능 항목으로 선언해야합니다. 관찰 가능한과

function AppViewModel() { 
    var self = this; 
    self.MyOptions = ko.observableArray([ 
     {id: 'a1', name: 'One'}, 
     {id: 'a2', name: 'Two'}, 
     {id: 'a3', name: 'Three'} 
    ]); 

    self.Data = ko.observableArray([ 
     {idOpt: ko.observable('a1')}, 
     {idOpt: ko.observable('a2')}, 
     {idOpt: ko.observable('a1')} 
    ]); 
} 

var vm = new AppViewModel(); 
ko.applyBindings(vm); 
녹아웃 문서는 당신에게 일반 모델을 사용 사이의 차이를 보여줍니다

다음 모델 http://knockoutjs.com/documentation/observables.html

관련 문제