I have my module, as defined here:
import ko = require("knockout");
import http = require("services/http");
class ProductSearch {
searchText = ko.observable<string>();
products = ko.observableArray();
submitSearch = () => {
http.get(`api/playground/customer/6B4F8534-1580-4973-A379-E2F26DF08D26/products`, { q: this.searchText() })
.done(this.displayResults);
};
displayResults = (results) => {
ko.mapping.fromJS(results, this.products);
};
}
export = ProductSearch;
However, when it runs, the ko.mapping.fromJS()
call does not appear to be updating the products
array at all. I didn't want to clear it and add the items in by hand (which I have confirmed works), as I was led to believe that ko.mapping could manage all that for me, including attempting to maintain the order of items in the array.
Is there something I'm doing wrong?