我有一个语法问题,这就是为什么我不能正确地解决我的问题,但我会再次尝试澄清我是否可以。我有一种形式的杂货饼干,我将它们放在一个模态中。在数据表中,有一个按钮,我可以选择编辑,查看或删除记录。这些按钮功能的内部是上面提到的代码。在上面的代码中,当我单击编辑按钮时,它将显示带有编辑表单的模态,依此类推。在list.php,我在下面声明了一个javascript变量,在那里我从groceryCrud获得编辑和查看链接。
问题是,当我点击编辑和查看按钮时,我无法获取数据表中所选数据的ID。它将获取并显示模态中最新输入的数据/记录。声明我的javascript变量是否有什么不对,这就是为什么我无法获得与我选择的记录的确切ID一起使用crud操作的链接?
我的代码位于datatables/view/list.php
<table class="table table-striped table-bordered table-vcenter table-condensed table-responsive table-hover" id="example-datatable" style="height: 50px;">
<thead>
<tr>
<center>
<?php foreach ($columns as $column) {?>
<th><?php echo $column->display_as;?></th>
<?php }
?>
<?php if (!$unset_delete || !$unset_edit || !$unset_read || !empty($actions)) {?>
<th class="text-center actions" title="Actions" data-sortable="false"><i class="fa fa-flash"></i></th>
<?php }
?>
</center>
</tr>
</thead>
<tbody>
<?php foreach ($list as $num_row => $row) {
?>
<tr id='row-<?php echo $num_row?>'>
<?php foreach ($columns as $column) {?>
<td><?php echo $row->{$column->field_name}?></td>
<?php }
?>
<?php if (!$unset_delete || !$unset_edit || !$unset_read || !empty($actions)) {
?>
<td class="text-center">
<?php
if (!empty($row->action_urls)) {
foreach ($row->action_urls as $action_unique_id => $action_url) {
$action = $actions[$action_unique_id];
?>
<a href="<?php echo $action_url;?>" class="edit_button btn btn-small btn-effect-ripple btn-ripple btn-default row col-sm-4 col-xs-4" role="button">
<span class="ui-button-icon-primary ui-icon <?php echo $action->css_class;?> <?php echo $action_unique_id;?>"></span><span class="ui-button-text"> <?php echo $action->label?></span>
</a>
<?php
}
}
?>
<?php if (!$unset_read) {?>
<!-- <a href="<?php // echo $row->read_url ?>" class="edit_button ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" role="button">
<span class="ui-button-icon-primary ui-icon ui-icon-document"></span>
<span class="ui-button-text"> <?php // echo $this->l('list_view'); ?></span>
</a>-->
<a href="#modal-fadeView" class="btn btn-effect-ripple btn-xs btn-primary viewBtn" data-toggle="modal" title="<?php echo $this->l('list_view');?>" role="button" style="overflow: hidden; position: relative;">
<i class="fa fa-info-circle"></i>
</a>
<?php }
?>
<?php if (!$unset_edit) {?>
<!-- <a href="<?php // echo $row->edit_url ?>" class="edit_button ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" role="button">
<span class="ui-button-icon-primary ui-icon ui-icon-pencil"></span>
<span class="ui-button-text"> <?php // echo $this->l('list_edit'); ?></span>
</a>-->
<a href="#modal-fadeEdit" class="edit_button btn btn-effect-ripple btn-xs btn-success editBtn" data-toggle="modal" title="<?php echo $this->l('list_edit');?>" role="button" style="overflow: hidden; position: relative;">
<i class="fa fa-pencil"></i>
</a>
<?php }
?>
<?php if (!$unset_delete) {?>
<!-- <a onclick = "javascript: return delete_row('<?php // echo $row->delete_url ?>', '<?php // echo $num_row ?>')"
href="javascript:void(0)" class="delete_button ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" role="button">
<span class="ui-button-icon-primary ui-icon ui-icon-circle-minus"></span>
<span class="ui-button-text"> <?php // echo $this->l('list_delete'); ?></span>
</a>-->
<a onclick = "javascript: return delete_row('<?php echo $row->delete_url?>', '<?php echo $num_row?>')"
href="javascript:void(0)" class="delete_button btn btn-effect-ripple btn-xs btn-danger" title="<?php echo $this->l('list_delete');?>" role="button">
<i class="fa fa-times"></i>
</a>
<?php }
?>
</td>
<?php }
?>
</tr>
<?php }
?>
</tbody>
<!-- <tfoot>
<tr>
<?php foreach ($columns as $column) {?>
<th><input type="text" name="<?php echo $column->field_name;?>" placeholder="<?php echo $this->l('list_search') . ' ' . $column->display_as;?>" class="search_<?php echo $column->field_name;?>" /></th>
<?php }
?>
<?php if (!$unset_delete || !$unset_edit || !$unset_read || !empty($actions)) {?>
<th>
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only floatR refresh-data" role="button" data-url="<?php echo $ajax_list_url;?>">
<span class="ui-button-icon-primary ui-icon ui-icon-refresh"></span><span class="ui-button-text"> </span>
</button>
<a href="javascript:void(0)" role="button" class="clear-filtering ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary floatR">
<span class="ui-button-icon-primary ui-icon ui-icon-arrowrefresh-1-e"></span>
<span class="ui-button-text"><?php echo $this->l('list_clear_filtering');?></span>
</a>
</th>
<?php }
?>
</tr>
</tfoot>-->
</table>
<!--<script type="text/javascript" src="<?=base_url()?>assets/Backend/grocery_crud/js/jquery_plugins/jquery.fancybox.pack-2.1.5.js"> </script>-->
<script type="text/javascript">
var editUrl = "<?php echo $row->edit_url?>",
readUrl = "<?php echo $row->read_url?>";
var $ = jQuery.noConflict();
$(document).ready(function () {
$(".fancybox").fancybox();
});
</script>
在下面的<script>
标记内,我声明了crud操作链接的变量。我有这个js文件:
$(".addBtn").click(function () {
$('#addFrame').attr('src', "/InfoTable/add");
});
$(".editBtn").click(function () {
$('#editFrame').attr('src', editUrl);
});
$(".viewBtn").click(function () {
$('#viewFrame').attr('src', readUrl);
});
现在,我无法获得crud操作与数据id的确切链接,当我单击编辑和查看按钮时,它获取最新输入/添加的数据ID。对不起我的语法,希望大家都明白。 任何帮助和建议都是天赐受到尊重的。提前致谢! :)