Change observable value on dropdown change Knockout Js

后端 未结 2 1409
清酒与你
清酒与你 2021-02-04 11:21

I have this dropdown which have options if vehicle is new or used.


     
     





The JS:

var ViewModel = function() {
    this.VehicleType = ko.observable();
    this.Mileage = ko.observable();

    this.VehicleType.subscribe(function(newValue) {
        if (newValue === "New") {
            this.Mileage(0);
        }
    }, this);
};

ko.applyBindings(new ViewModel());

提交回复
热议问题