我有我的模块,如下所示:
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;
但是,当它运行时,ko.mapping.fromJS()
调用似乎根本不更新products
数组。我不想清除它并手动添加项目(我已确认其作品),因为我被认为ko.mapping可以为我管理所有这些,包括尝试维护项目的顺序在阵列中。
我做错了吗?