【发布时间】:2015-02-10 01:26:52
【问题描述】:
当我运行我的应用程序时,我得到:“Uncaught TypeError: Cannot read property 'init' of undefined” 文档准备函数中的警报运行,所以我知道此时已加载 jQuery。但我不知道为什么 Task 是未定义的。
这是一个 MVC5 应用程序,运行 jQuery 1.10.2
请帮忙,jsFiddle 工作正常,JsHint 没有显示错误。
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: $('#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();
});
【问题讨论】:
-
我赞成只是因为我不知道
return不允许它的值从后续行开始(每个 JS 编码人员都应该知道):)
标签: javascript jquery model-view-controller module-pattern