使用knockout绑定将错误绑定到UI页面时,我遇到了一些小问题。请帮帮我
var searchObj = { model defination }
if (!ko.validatedObservable(searchObj).isValid()) {
ko.validation.group(searchObj);
return false;
}
<ul data-bind='foreach: $root.errors' class="message">
<li>
<span data-bind='text: $data'></span>
</li>
</ul>
ko.validation.init({
registerExtenders: true,
decorateElement: true,
errorElementClass: 'errorMessage',
insertMessages: false,
// messagesOnModified: false,
// errorsAsTitle: true
});
答案 0 :(得分:0)
<div class="errorSummary" data-bind="if: searchCriteria.Errors().length">
<ul data-bind='foreach: searchCriteria.Errors'>
<li>
<div data-bind='text: $data'></div>
</li>
</ul>
</div>
ko.validation.init({
registerExtenders: true,
decorateElement: true,
errorElementClass: 'errorMessage',
insertMessages: false,
messagesOnModified: false
// errorsAsTitle: true
});
return {
Errors: searchObj.errors;
}