"TypeError: t.validation is undefined",但它似乎已定义



我有一个jQuery UI对话框,当在对话框中按下按钮时,我正在尝试验证输入。

但是,当我单击"添加"按钮并告诉我TypeError: t.validation is undefined时,它失败了。据我所知,它是定义的(在init函数中)。

怀疑我设置不正确,但我看不到在哪里查找。有人可以告诉我如何解决此错误吗?

$(document).ready(function(){
    optionsDialogFuncs.init();
});
optionsDialogFuncs = {
    /**
     * Constructor
     */
    init : function(){
        var t = this;   // This object
        $('#add_option').on('click', function(){
            /** Create an object to hold the result of validation checks and the final result */
            t.validtaion = {};
            t.add_option();
        });
    }, // init
    /** Add a single option to the list of predefined options */
    add_option : function(){
        var t = this;   // This object
            tip = $('.validation-tip', '#add-remove-options-form');
        t.validate_add_option();
        /** Check to see if the option was valid */
        if(t.validation.valid !== true){
            /** Output a validation tip to help the user */
            if(t.validation.exists === false){
                tip.text('Please enter an option.');
            } else if(t.validation.exists === false){
                tip.text('This option already exists.');
            } else{
                tip.text('An unknow validation error occured. Please try again.');
            }
        } else{
            // Append input to list of options
            // Update the 'poll_options' textarea
            // Update the dialog display
        }
    }, // add_option
    validate_add_option : function(){
        var t = this,                                   // This object
            new_option = $('#new_option').val(),        // The new option that the user wishes to add
            options_text = $('#poll_options').text(),   // The text form the predefined options textarea, i.e. any existing options
            options = options_text.split("n");         // The predefiend options as an array
        /** Check to see if this option already exists */
        t.validation.empty = (new_option === '') ? true : false;
        /** Check to see if this option already exists */
        t.validation.exists = $.inArray(new_option, options);
        /** Ensure the option passed all validity checks */
        t.validation.valid = (t.validation.empty === false && t.validation.exists === -1) ? true : false;
    } // validate_add_option
};

你拼错了变量。

// this 
t.validtaion = {};
// should be 
t.validation = {}; 

相关内容

最新更新