我无法弄清楚为什么它总是返回null。即使文本框值具有新值。
self.update = function (data, event) {
if (event.keyCode === 13 || event.type === "blur") {
console.log(self.getPercentById(event.target.value)); // always null
}
return true;
};
self.getPercentById = function (percent) {
return ko.utils.arrayFirst(self.List(), function (item) {
return item.Percent() === percent;
});
};
视图模型
function ViewModel() {
var self = this;
self.url = ko.observable(document.URL.substr(document.URL.lastIndexOf('/') + 1));
self.activeSort = ko.observable();
self.sortColumn = null;
self.selected = ko.observableArray()(false);
self.allSelected = ko.observable(false);
self.selectedItem = ko.observable(null);
self.List = ko.observableArray();
self.sort = function (items, event) {
...