Ответ 1
Вот код, который создает расширители проверки.
addExtender: function (ruleName) {
ko.extenders[ruleName] = function (observable, params) {
//params can come in a few flavors
// 1. Just the params to be passed to the validator
// 2. An object containing the Message to be used and the Params to pass to the validator
//
// Example:
// var test = ko.observable(3).extend({
// max: {
// message: 'This special field has a Max of {0}',
// params: 2
// }
// )};
//
if (params.message) { //if it has a message object, then its an object literal to use
return ko.validation.addRule(observable, {
rule: ruleName,
message: params.message,
params: params.params || true
});
} else {
return ko.validation.addRule(observable, {
rule: ruleName,
params: params
});
}
};
},
Как вы можете видеть, все расширения могут получать объект params или литерал объекта с параметрами и настраиваемым сообщением. Так что в вашем случае.
var numberValue = ko.observable().extend({ number: {
message: "some custom message",
params: true
} })
Надеюсь, что это поможет.