gpt4 book ai didi

javascript - 刷新 Bootstrap 表

转载 作者:数据小太阳 更新时间:2023-10-29 06:05:42 31 4
gpt4 key购买 nike

问题是我无法在完成注册后让表(bootstrap-table)更新数据。我正在尝试通过 JS 来完成,但没有成功。我尝试了以下方法:

JS

$.post($form.attr('action'), $form.serialize(), function (result) {
if (result.status == "true") {
$(location).attr('href', result.acao.url);
} else {
$('#cargo').formValidation('resetForm', true)
$('#cadastroCargo').modal('hide')
//ATTEMPT REFRESH BOOTSTRAP-TABLE:
$('#teste').bootstrapTable('refresh')
}
}, 'json');

HTML/PHP

    <button class="btn btn-primary pull-right btn-import-user btn-sm" data-toggle="modal" data-target="#cadastroCargo">Novo Cadastro</button>

<!-- Modal -->
<div class="modal fade" id="cadastroCargo" tabindex="-1" data-keyboard="false" data-backdrop="static" role="dialog" aria-labelledby="cargoLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form id="cargo" action="Cargo/inserir" method="POST" enctype="multipart/form-data" autocomplete="off">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="cargoLabel">Cadastrar Cargo</h4>
</div>
<div class="modal-body">
<fieldset>
<div class="form-group">
<label class="modal-font-body control-label">Informe o Cargo</label>
<input name="titulo" type="text" class="form-control input-sm" id="titulo" data-minlength="4" size="35" value="<?= @$cargo->titulo ?>" data-error="Por favor, preencha este campo corretamente!" required>
<input type="hidden" name="id" value="<?= @$cargo->id ?>">
<input type="reset" id="configreset" value="reset" hidden>
</div>
<div id="mensagemSucesso" class="alert alert-success alerta-sucesso" hidden></div>
</fieldset>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
<input type="submit" id="salvar" value="Salvar" name="salvar" class="btn btn-primary">
</div>
</form>
</div>
</div>
</div>

<table id="teste" name="teste" class="table table-striped" data-toggle="table" data-search="true" data-show-refresh="true" data-show-columns="true"
<thead>
<tr>
<th class="th-small" data-align="left" data-sortable="true">ID</th>
<th data-align="left" data-sortable="true">Nome</th>
<th class="th-small">Ações</th>
</tr>
</thead>
<tbody>
<?php
foreach ($cargo as $key => $v) {
?>
<tr>
<td><?= $v->id ?></td>
<td><?= $v->titulo ?></td>
<td>
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="submit" data-toggle="dropdown">... <span class="caret"></span></button>
<ul class="table-modal dropdown-menu">
<li><a data-remote="Cargo/page/visualizar/<?= $v->id ?>" role="button" data-toggle="modal" data-target="#select-modal">Visualizar</a></li>
<li><a data-remote="Cargo/page/alterar/<?= $v->id ?>" data-toggle="modal" data-target="#editarIdade">Editar</a></li>
</ul>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>

最佳答案

1) 在名为data-url的表格上填写html标签

2) 当需要刷新时调用js函数$('#teste').bootstrapTable('refresh')

关于javascript - 刷新 Bootstrap 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35319401/

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