1
여기는 fiddle입니다.왜 뷰 모델의 속성을 변경 한 후에 applyBindings를 다시 호출해야합니까?
일부 사용자 상호 작용 후에 데이터의 일부를 사용할 수있는 뷰 모델이 있습니다.
applyBindings
은 문서 준비가 완료 될 때 이미 호출되었으므로 버튼 클릭 이벤트 중에 다시 호출해야하는 이유는 무엇입니까?
HTML :
<p>first name:
<input type="text" data-bind="value: ray.firstName" />
</p>
<p>last name:
<input type="text" data-bind="value: ray.lastName" />
</p>
<p>first name:
<input type="text" data-bind="value: joe.firstName" />
</p>
<p>last name:
<input type="text" data-bind="value: joe.lastName" />
</p>
JS :
function person(firstNm, lastNm) {
this.firstName = firstNm;
this.lastName = lastNm;
}
function myApp() {
this.ray = new person();
this.joe = new person();
}
var app = new myApp();
app.ray = new person('ray', 'cheng');
ko.applyBindings(app);
$('#showName').on('click', function() {
app.joe = new person('joe', 'public');
ko.applyBindings(app); // <-- why is this needed since applyBindings already called above.
});
knockout.js의 [튜토리얼] (http://learn.knockoutjs.com/)을 방문하는 것이 좋습니다. 그들은 매우 도움이됩니다. –