Trying to add an item to an observableArray in knockout. While the item is certainly being added to the view model, it is not being added to the view. Seems to be something to do with using ko.mapping.fromJS. Recreated the problem I am facing here:
function ViewModel() {
var vm = {
props: ko.observableArray(["A", "B"]),
field: ko.observable(""),
val: "Some value"
};
vm.field.subscribe(function () {
vm.props.push("C");
});
return vm;
}
var myVM = new ViewModel();
myVM = ko.mapping.fromJS(myVM);
ko.applyBindings(myVM, document.getElementById("c"));
HTML:
<div id="c">
<select data-bind="options: props"></select>
<input data-bind="value: field">
<span data-bind="text: val"></span>
</div>
When you enter something into the text box the drop down list does not update.