문제

나는 knockout.js 뷰 모델을 뷰에 중첩 할 수있는 어레이를 가지고 있습니다.

   function ParentVM(data) {
        var self = this;

        self.childs= ko.observableArray([]);
        ko.mapping.fromJS(data, mapping, this);
    }

    function ChildVM(data) {
        var self = this;

        self.propertyA = ko.observableArray([]);
        self.propertyB = ko.observable();

        ko.mapping.fromJS(data, mapping, this);
    }

    function GrandChildVM(data) {
        var self = this;

        self.propertyX = ko.observable();
        self.propertyY = ko.observable();
        self.propertyZ = ko.observable();

        ko.mapping.fromJS(data, mapping, this);
    }
.

나는 바인딩을 따른다 :

 data-bind="value: propertyX, valueUpdate: 'keydown'"
.

이제, 이벤트 핸들러를 추가하여 이러한 등록 정보가 변경되면 뷰 모델 상태를 업데이트하기 위해 내 휴식 핸들러를 추가하려면 어떻게해야합니까?

도움이 되었습니까?

해결책

내가 당신을 정확하게 이해하면 이것이 할 수있는 것입니다 :

function ChildVM(data) {
    var self = this;

    self.propertyA = ko.observableArray([]);
    self.propertyB = ko.observable();

    ko.mapping.fromJS(data, mapping, this);

    self.propertyA.subscribe(function (newValue) { /* call you're api with new value! */ });
    self.propertyB.subscribe(function (newValue) { /* call you're api with new value! */ });
}
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top