Javascript jQuery-编辑模式中值的catch行字段
在“表格行编辑”按钮上单击,将打开一个表格模式 我选择该行的当前值,以便在打开modal时它们可以作为该表单字段的默认值 由于我是jQuery新手,我不知道如何在其他方法中传递该值 我的职责:Javascript jQuery-编辑模式中值的catch行字段,javascript,jquery,ajax,function,parameters,Javascript,Jquery,Ajax,Function,Parameters,在“表格行编辑”按钮上单击,将打开一个表格模式 我选择该行的当前值,以便在打开modal时它们可以作为该表单字段的默认值 由于我是jQuery新手,我不知道如何在其他方法中传递该值 我的职责: var $fruitForm = $('#edit-form') $('.fruit_edit').on('click', function(event) { // Get the data-id value of the modal link. var id = $(this).da
var $fruitForm = $('#edit-form')
$('.fruit_edit').on('click', function(event) {
// Get the data-id value of the modal link.
var id = $(this).data('fruit_id');
// Set the hidden input field with the id.
$('#fruit_id').val(id);
var $row = $(this).closest('tr');
// Here I am finding row value on click
var tableFruitName = $("a[data-fruit_id="+id+"]").closest("tr").find('.tableFruitName').text()
event.preventDefault();
});
// Listen for submit instead of click.
$fruitForm.on('submit', function(event) {
event.preventDefault();
// Get the values from the form.
var $form = $(this);
var id = $form.find('input[name="fruit_id"]').val();
I want for the value from upper 'onclick' to be defined in from input here
var fruitName = $('#fruitName').val(tableFruitName);
$.ajax({
type: 'PATCH',
url: '/fruit/edit',
data: JSON.stringify({
'id' : id,
'fruitName' : fruitName
}),
processData: false,
contentType: 'application/json-patch+json',
success: function () {
$("#fruit-table").load(location.href + " #fruit-table");
$('#editFruit').modal('hide');
},
error: function (xhr, status, error) {
var ErrorMessage = JSON.parse(xhr.responseText);
}
});
});
我的工作流程说明在评论中。我不知道如何在定义输入的其他方法中传递捕获的值
<tr>
<td class="text-center"> {{ fruit.id }} </td>
<td class="text-center tableFruitName"> {{fruit.fruitName is empty ? "N/A" : fruit.startDate }}</td>
<td class="td-actions text-center">
<a href data-toggle="modal" data-target="#editFruit" data-fruit_id="{{ fruit.id }}" class="btn btn-warning fruit_edit">
<i class="fa fa-fw fa-pencil"></i>
</a>
</td>
</tr>
{{fruit.id}
{{fruit.fruitName为空?“不适用”:fruit.startDate}
能否显示您的表格结构?谢谢您的重播。我更新了我的帖子@SwatiHi这样尝试->$([data-fruit_id=“+id+”])。最近的(“tr”)。查找('.tableFruitName')。text()
是,当我打开console.log()时,它会显示精确的值,但当我打开时,模态属性值不会插入到该表单字段中?这就是主要问题所在@SwatiDeclare thisvar tablefurtname代码>全局超出事件处理程序,那么它的值将在整个程序中可用。另外,你说的是哪个表单字段?你能显示你的表结构吗?谢谢你的重播。我更新了我的帖子@SwatiHi这样尝试->$([data-fruit_id=“+id+”])。最近的(“tr”)。查找('.tableFruitName')。text()
是,当我打开console.log()时,它会显示精确的值,但当我打开时,模态属性值不会插入到该表单字段中?这就是主要问题所在@SwatiDeclare thisvar tablefurtname代码>全局超出事件处理程序,那么它的值将在整个程序中可用。你说的是哪个表单字段?