我正在尝试访问SignalR连接函数内的函数。为了更好地说明这是整个脚本的代码。
$(function() {
var chat = $.connection.chatHub;
chat.client.informOfStatusRequest = function(personToNotify, message) {
var sysUserId = @Convert.ToInt32(HttpContext.Current.Request.Cookies["sys_user_id"].Value);
if (sysUserId === personToNotify) {
$.notify({
icon: 'glyphicon glyphicon-star',
message: message
}, {
animate: {
enter: 'animated fadeInRight',
exit: 'animated fadeOutRight'
}
});
}
}
$.connection.hub.start().done(function() {
function disapproveTicket(ticketId, createdById) {
bootbox.confirm({
title: 'CONFIRM',
message: 'Disapprove ticket ID ' +ticketId +'?',
buttons: {
confirm: {
label: 'YES',
className: 'btn-success'
},
cancel: {
label: 'NO',
className: 'btn-danger'
}
},
callback: function(response) {
if (response === true) {
$.ajax({
type: 'POST',
url: '/Member/DisapprovePendingTicket',
data: {ticketId: ticketId} ,
success: function(result) {
if (result === true) {
$.notify({
icon: 'glyphicon glyphicon-star',
message: "Ticket has been disaproved"
}, {
animate: {
enter: 'animated bounceIn',
exit: 'animated bounceOut'
}
}, {
type: 'success'
});
$("#div_get_pending_ticket").load('/Member/GetPendingTicket');
getPendingRequestCount();
chat.server.informUserOnRequestStatus(createdById,"Ticket has been disaproved");
} else {
$.notify({
icon: 'glyphicon glyphicon-star',
message: "Failed in disapproving the ticket."
}, {
animate: {
enter: 'animated bounceIn',
exit: 'animated bounceOut'
}
}, {
type: 'success'
});
}
}
});
}
}
});
}
});
});
这就是我尝试访问“disapproveTicket”功能的方法:
<td>
<a href="javascript:void(0);" onclick="">Check</a> |
<a href="javascript:void(0);" onclick="disapproveTicket(@item.TicketId, @item.CreatedById)">Disapprove</a>
</td>
在我的控制台上,它说“不赞成游戏未定义”。 disapproveTicket位于$(function())内,位于$ .connection.hub.start()。done()内。我已经看到了关于如何访问嵌套函数的其他答案,但结构与我的结构不同。你能告诉我吗?谢谢。
答案 0 :(得分:0)
我看到你的函数disapproveTicket()可以在$ .connection.hub.start()。done()时使用。这样html元素中的onclick属性就无法调用它。我认为你必须使用
$.connection.hub.start().done(function(){
$("#your_element").click(function(){
disapproveTicket()
})
})
希望这可以帮到你