ko.applyBindings({
candidateList: [{ id: 1, title: "first" }, { id: 2, title: "second" }, { id: 3, title: "third" }],
setOptionTitle: function() { },
selectedCandidates: ko.observableArray(),
addSelectedCandidate: function() { },
candidateChanged: function() { },
enabled: ko.observable(true)
});
function getRandomVal() { return (Math.floor(Math.random() * (3 - 1)) + 1).toString(); }
window.setInterval(function() {
var vals = [];
if (Math.random() > 0.75) { vals.push(getRandomVal()); }
if (Math.random() > 0.75) { vals.push(getRandomVal()); }
if (Math.random() > 0.75) { vals.push(getRandomVal()); }
$("select").val(vals).trigger("change");
}, 1000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-min.js"></script>
<select multiple="multiple" data-bind="options: candidateList, optionsValue: 'id', optionsText: 'title', optionsAfterRender: setOptionTitle, selectedOptions: selectedCandidates, optionsAfterRender: setOptionTitle, event: { dblclick: addSelectedCandidate, change: candidateChanged }, enable: enabled()">
<option title="first" value="1">first</option>
<option title="second" value="2">second</option>
<option title="third" value="3">third</option>
</select>
<hr>
Selected candidates: <code data-bind="text: ko.toJSON($root.selectedCandidates, null, 2)"></code>