为什么应用程序找不到我的JS类(模块模式)MVC [英] Why can't application find my JS class (module pattern) MVC

查看:156
本文介绍了为什么应用程序找不到我的JS类(模块模式)MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提醒:愚蠢的问题



我有task.js文件,其中有一个名为Task的类,使用显示的模块化模式。



我正在研究一个MVC应用程序,我已经检查过HTML Jquery库在我的JS脚本之前加载了,下面的JS文件内容代码如下。 />


文件显示为HTML(最后)加载,Network:Scripts in developer tools。



如果我使用该类的文字模式,该应用程序可以工作。

为什么它不适用于模块模式?我一直都使用这种模式而没有这个问题,我做错了什么?



错误:



Uncaught TypeError:无法读取未定义的属性'init'


Alert: Stupid Question

I have task.js file, with a class called Task in it, using the revealing modular pattern.

i'm working on a MVC application, and i've checked the HTML Jquery library gets loaded before my JS script, the following code for the contents of my JS file is below.

the file shows as loaded in the HTML (last), and Network:Scripts in developer tools.

The app works if i use the literal pattern for the class.
Why will it not work with the module pattern? I've used this pattern all the time and not had this problem, what am i doing wrong?

Error:

"Uncaught TypeError: Cannot read property 'init' of undefined"


var Task = (function () {

    var initialize = function () {
        console.log($);
        bindEvents();
    };
    var postFilter = function () {
        console.log("clicked");
        var postData = {
            UserID: $('#user_select').val,
            TaskTypeID: $('#taskTypeSelect').val,
            TaskStatusID: S('#status_select').val,
            PriorityID: $('#priority_select').val
        };

        $.ajax({
            url: "/Tasks/_AllTaskView",
            data: postData,
            success: function (response) {
                $('#results').html(response);
            }

        });
    };

    var bindEvents = function () {
        $('#submit_filter').on('click', postFilter);
    };

    return
    {
        init : initialize

    };

})();

$(document).ready(function () {
    alert()
    Task.init();
});

推荐答案

);
bindEvents();
};
var postFilter = function(){
console.log( 点击);
var postData = {
UserID:
); bindEvents(); }; var postFilter = function () { console.log("clicked"); var postData = { UserID:


' #user_select')。val,
TaskTypeID:
('#user_select').val, TaskTypeID:


' #taskTypeSelect')。val,
TaskStatusID:S(' #status_select')。val,
PriorityID:
('#taskTypeSelect').val, TaskStatusID: S('#status_select').val, PriorityID:


这篇关于为什么应用程序找不到我的JS类(模块模式)MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆