JSFiddle - React, Tailwind, and code Playground
by Salmin Skenderovic
HTML
<input type="checkbox" data-bind="checked: checkbox"><br>
<p data-bind="text: selected"></p><br>
<select data-bind="options: myArray, value: selected"></select>
JavaScript
function ViewModel() {
this.checkbox = ko.observable(false);
this.firstItem = ["this one should be selected if true"];
this.staticArray = ["selected if false", "2", "3", "4", "5", "6"];
this.myArray = ko.computed(function() {
if (this.checkbox()) {
console.log("a");
return this.firstItem;
} else {
console.log("b");
return this.staticArray;
}
}, this);
this.selected = ko.observable();
checkbox.subscribe(function(checked) {
});
}
//
window.onload = function(){
ko.applyBindings(ViewModel());
}