我有一个可观察的可观察数组 - 每个可观察的数组都已针对要求进行了扩展,但是当我保存带有清除字段的表单时,它不会收集错误或显示任何错误 -
ko.validation.configure({
grouping: {
deep: true,
observable: true
}
});
var viewModel = function () {
var self = this;
var data = {
"deadzone": "0.2",
"sloperange": "2",
"stepsize": "0.8",
"setpoint": "0.75",
"pressure": "1"
};
self.defaultCalculations = ko.observableArray([]);
self.defaultCalculationProperties = function (defaults) {
var self = this;
var properties = defaults;
self.deadzone = ko.observable(properties.deadzone || '').extend({
required: {
message: '*required'
}
});
self.sloperange = ko.observable(properties.sloperange || '').extend({
required: {
message: '*required'
}
});
self.stepsize = ko.observable(properties.stepsize || '').extend({
required: {
message: '*required'
}
});
self.setpoint = ko.observable(properties.setpoint || '').extend({
required: {
message: '*required'
}
});
self.pressure = ko.observable(properties.pressure || '').extend({
required: {
message: '*required'
}
});
};
//populate calculation values
self.populateCalculationDefaults = function (data) {
//pushing data to an array and mapping each item
var temp = [];
temp[0] = data;
var mappedTasks = _.map(temp, function (item) {
return new self.defaultCalculationProperties(item);
});
self.defaultCalculations(mappedTasks);
};
self.save = function (model) {
//console.log(model);
console.log(self.errors().length, self.errors.showAllMessages());
if (self.errors().length != 0) {
self.errors.showAllMessages();
}
};
self.errors = ko.validation.group(self.defaultCalculations());
self.populateCalculationDefaults(data);
};
ko.applyBindings(new viewModel());
不确定问题是什么,并且已经搜索过 stackflow - 有什么建议吗?