gpt4 book ai didi

javascript - 意外 -> userSelect.on 'valuesChanged' ->

转载 作者:行者123 更新时间:2023-12-03 05:55:23 34 4
gpt4 key购买 nike

我从 challengers.coffee 运行此代码,并收到错误 ActionView::Template::Error (SyntaxError: [stdin]:3:31:unexpected ->,我能够进一步提炼(参见第 #3 行的评论):

$(document).ready ->
userSelect = $('#change-challenge-options')
userSelect.on 'valuesChanged' ->
currentUserId = $('#current-challenge-options').data('current-user-id')
if(currentUserId == userSelect.val())
$('#current-user-challenges').show()
$('#challenged_user_challenges').hide()
else
$('#challenged_user_challenges').show()
$('#current-user-challenges').hide()

dueler/_dueler_fields.html.erb

<%= f.select :user_id, User.order(:name).map { |user| [user.full_name, user.id] }, include_blank: true, id: "change-challenge-options", data: {current_user_id: current_user.id } %> will

<%= collection_select(:dueler, :challenge_id, @current_user_challenges, :id, :full_challenge, include_blank: true, id: "current-user-challenges") %>
<%= collection_select(:dueler, :challenge_id, @challenged_user_challenges, :id, :full_challenge, include_blank: true, id: "challenged_user_challenges") %>

最佳答案

-> 之前缺少一个逗号。代码应如下所示(我还删除了 if 语句中的括号):

$(document).ready ->
userSelect = $('#change-challenge-options')
userSelect.on 'valuesChanged', ->
currentUserId = $('#current-challenge-options').data('current-user-id')
if currentUserId == userSelect.val()
$('#current-user-challenges').show()
$('#challenged_user_challenges').hide()
else
$('#challenged_user_challenges').show()
$('#current-user-challenges').hide()

关于javascript - 意外 -> userSelect.on 'valuesChanged' ->,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39951354/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com