【发布时间】:2019-08-15 11:48:03
【问题描述】:
我有这个工作,但一定是在某个地方做了一个小改动,导致它停止工作。
单击按钮时我调用了 Javascript,但是当我单击按钮时没有加载任何内容。我已经多次检查了代码的所有部分,但看不到故障发生在哪里,并且日志中没有任何反馈,所以我无事可做。
正如我所说,它以前可以工作,但后来停止了。
这是我的按钮:
<%= button_tag t(".change"), class: "btn let-admin-change",
data: { title: t(".confirm_switch"),
cancel: t(".cancel"),
cta: t(".confirm_cta"),
plot: plot.id } %>
还有我的 javascript 文件:
(function (document, $) {
'use strict'
$(document).on('click', '.let-admin-change', function (event) {
var dataIn = $(this).data()
var $changeContainer = $('.change-admin-letting-form')
$('body').append($changeContainer)
var $form = $('.edit_plot')
$changeContainer.dialog({
show: 'show',
modal: true,
width: 700,
title: dataIn.title,
buttons: [
{
text: dataIn.cancel,
class: 'btn',
click: function () {
$(this).dialog('destroy')
}
},
{
text: dataIn.cta,
class: 'btn-send btn',
id: 'btn_submit',
click: function () {
$.ajax({
url: '/plots/' + dataIn.plot,
data: $form.serialize(),
type: 'PUT'
})
$(this).dialog('destroy')
$changeContainer.hide()
}
}]
}).prev().find('.ui-dialog-titlebar-close').hide() // Hide the standard close button
})
})(document, window.jQuery)
以及它调用的形式:
<div class="change-admin-letting-form">
<%= simple_form_for plot, url: phase_lettings_path(@phase), remote: true do |f| %>
<div>
<%= f.hidden_field :letter_type, value: :homeowner %>
<%= f.hidden_field :letable_type, value: :planet_rent %>
</div>
<div>
<h3><%= t(".are_you_sure", plot: plot) %></h3>
<p><%= t(".confirm_admin_swap").html_safe %></p>
</div>
<% end %>
</div>
谁能看到阻止 javascript 加载的问题在哪里?
编辑
如果我添加
<%= render "change_admin_letting_form", plot: plot %>
在按钮下方,然后加载表单(但它加载多个表单 - 每个按钮实例一个表单/页面上的每个绘图),所以我认为问题是绘图信息没有传递给表单?我不确定如何传递这些信息。
【问题讨论】:
-
“正如我所说,它之前可以工作,但后来停止了。” - 啊,这是最简单的错误。只需恢复到已知的良好状态,再次一点一点地重新引入更改,然后看看它在哪里中断。
标签: javascript ruby-on-rails ruby