I´m having some finger trouble with this:
<p data-bind="text: $root.myArray()[0]"></p>
<hr>
myVal = <span data-bind="text: $root.myVal()></span>
In viewmodel:
self.myArray = ko.computed(function() {
var categories = ko.utils.arrayMap(self.selectedItems(), function(item) {
return item.id();
});
return categories.sort();
});
self.myVal = ko.observable(self.myArray()[0]);
Printing myArray shows the correct value, but myVal is blank. Why?
(and yes, I only want the first value in the array).
Also, I´d like it as a number when I save to database. Do I need to do some kind of typecast then?