jquery検証プラグインを使用して検証する反応アプリケーションにはフォームがあります。 this.initは反応アプリの関数jquery検証プラグインではありません
let validator = $('form').validate({
errorClass: 'has-error',
errorElement:'label',
});
validator.form();
if ($('.has-error').length > 0) {
$('.has-error').each(function (index) {
$.validator().showErrors({prop:$(this).data('error')});
});
} else {
/*work with data*/
}
すべてのエラーメッセージ
は罰金を示すが、検証がトリガーされるたびに、私は、コンソールにエラーが表示されます。this.init is not a function
を、プラグインスクリプト内のコードに私をリンクされています
$.validator = function(options, form) {
this.settings = $.extend(true, {}, $.validator.defaults, options);
this.currentForm = form;
this.init();
};
方法を私はそれを修正することはできますか? UPD 1:
$.extend($.validator, {
//some code
prototype: {
init: function() {
this.labelContainer = $(this.settings.errorLabelContainer);
this.errorContext = this.labelContainer.length && this.labelContainer || $(this.currentForm);
this.containers = $(this.settings.errorContainer).add(this.settings.errorLabelContainer);
this.submitted = {};
this.valueCache = {};
this.pendingRequest = 0;
this.pending = {};
this.invalid = {};
this.reset();
//some code
は多分それが原因で、このinit関数のエラー例外を発生させます:私はこのコードを見つけ、以下のプラグインのスクリプトコードに?
を持っていないグローバル
window
(またはstrict mode
でundefined
である)に、このファンクションポイント内で機能this
通常どおりにそれを呼び出す場合は? –私はinitメソッドを定義していません。プラグインスクリプト内で定義されています。更新された質問を参照してください。 –