【发布时间】:2017-05-21 11:56:23
【问题描述】:
我有以下咖啡脚本类:
class Teams
rankings: ->
this.nav_tabs_ajax_calls()
window.history.pushState(
'',
'',
CoffeeRoutes.path('rankings_team', { 'id': this.team_id() })
)
$('li.active').removeClass('active')
$('li:has(a[href="#rankings"])').addClass('active')
exercises: ->
this.nav_tabs_ajax_calls()
window.history.pushState(
'',
'',
CoffeeRoutes.path('exercises_team', { 'id': this.team_id() })
)
$('li.active').removeClass('active')
$('li:has(a[href="#exercises-list"])').addClass('active')
$(document).on 'click', '#add-exercise', ->
showModal("exercises", false, createModal);
createModal("exercises");
users: ->
window.history.pushState(
'',
'',
CoffeeRoutes.path('users_team', { 'id': this.team_id() })
)
$('li.active').removeClass('active')
$('li:has(a[href="#enrolled-students"])').addClass('active')
graph: ->
window.history.pushState(
'',
'',
CoffeeRoutes.path('graph_team', { 'id': this.team_id() })
)
$('li.active').removeClass('active')
$('li:has(a[href="#graph"])').addClass('active')
initialize_graph();
$('#pause-resume').click ->
if $('#pause-resume i').attr('class') == "fa fa-pause"
pause()
$('#pause-resume i').attr('class', 'fa fa-play')
$('#pause-resume i').attr('title', 'Resume graph animation')
else
resume()
$('#pause-resume i').attr('class', 'fa fa-pause')
$('#pause-resume i').attr('title', "Stop graph animation")
$('#back-center').click ->
reset()
$('#remove-graph').click ->
dispose()
$(document).on 'click', '#add-nodes', ->
showModal('search', false, createModal)
$(document).on 'click', '#search-btn', ->
div = $(document.createElement('div'))
div.attr('id', 'loading-modal')
$('.modal-content').append(div)
team_id: ->
$('#show-team').data('team-id')
nav_tabs_ajax_calls: ->
$('a[href="#rankings"]').click ->
$.ajax CoffeeRoutes.path('rankings_team', { 'id': this.team_id() })
type: 'GET',
dataType: 'script'
$('a[href="#exercises-list"]').click ->
$.ajax CoffeeRoutes.path('exercises_team', { 'id': this.team_id() })
type: "GET",
dataType: 'script'
$('a[href="#enrolled-students"]').click ->
$.ajax CoffeeRoutes.path('users_team', { 'id': this.team_id() })
type: "GET",
dataType: 'script'
$('a[href="#graph"]').click ->
$.ajax CoffeeRoutes.path('graph_team', { 'id': this.team_id() })
type: "GET",
dataType: 'script'
在my nav_tabs_ajax_calls 函数中,我收到以下错误(例如,如果我调用rankings 函数):Uncaught TypeError: this.team_id is not a function(…)。
从我的函数中删除this.nav_tabs_ajax_calls(),它工作正常,在我的其他函数中调用this.team_id() 没有错误。
我做错了什么,我该如何解决?
【问题讨论】: