我试图将数据填充到我的模态表单的下拉选项中,但似乎无效。该列表不会显示在我的下拉列表中。我不确定它有什么问题。感谢您的建议。 感谢
这是视图中的模态形式(view_timeline.php)
<div class="modal fade" id="myTimeModal" tabindex="-1" role="dialog" aria-labelledby="myTimeModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myTimeModalLabel">Add New Timeline</h4>
</div>
<form role="form" id="TimeForm" action="<?php echo base_url().'admin/addTimeline'; ?>" method= "POST">
<div class="modal-body">
<div class="form-group">
<label>Select Bank *</label>
<select name="fiid" id="fiid" class="form-control" onChange="fnLoadBank(this)" required=TRUE>
<option disabled selected>SELECT BANK</option>
</select>
</div>
// some other item
</div> <!-- end modal-body -->
<div class="modal-footer">
<button type="button" class="btn btn-default" id="reset" data-dismiss="modal">Cancel</button>
<button type="submit" value="submit" form="TimeForm" class="btn btn-primary"> Add Timeline</button>
</div> <!-- end modal-footer -->
</form>
这是我的javascript
<script type="text/javascript">
function fnLoadBank(me) {
$('.fiid').empty();
$('.fiid').html('<option disabled selected>SELECT BANK</option>');
$.ajax({
type:'POST',
url: '<?php echo base_url() ?>/admin/getBank()',
dataType: 'json',
success: function(dataBank) {
var str = '';
if (dataBank) {
$.each(dataBank, function(key, row) {
str += '<option value="' + row.bankID + '">' + row.bankName + '</option>';
});
$('.fiid').append(str);
}
}
});
}
</script>
这是我的admin / getBank控制器
public function getBank()
{
$dataBank = $this->model_bank->bank_getAll();
return $dataBank;
}
这是我的控制器加载view_timeline.php
public function index()
{
$data['dataBank'] = $this->model_bank->bank_getAll();
$this->load->view(pages/view_timeline,$data);
}
我的输出示例
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ BANK ID + BANK NAME + DATE/TIME + TRANSACTION DETAILS +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 0001 + BANK A + 1111/101210 + Transaction 1 +
+--------------------------------------------------------------+
+ 0002 + BANK B + 1111/103050 + Transaction 2 +
+--------------------------------------------------------------+
+ 0001 + BANK A + 1111/110105 + Transaction 3 +
+--------------------------------------------------------------+
+ADD MORE TRANSACTION+
因此,当点击ADD MORE TRANSACTION时,我需要选择银行(从可用银行列表中),填写详细信息并保存(添加到我的表中而不刷新我的页面)。因此,我使用模态来弹出表单。
答案 0 :(得分:0)
试试这个
<script type="text/javascript">
$(document).ready(function(e)
{
fnLoadBank();
});
function fnLoadBank()
{
$.ajax({
type:'POST',
url: '<?php echo base_url("admin/getBank");?>',
success: function(dataBank)
{
$('#fiid').html(dataBank);
}
}
});
}
</script>
<?php
public function getBank()
{
$dataBank = $this->model_bank->bank_getAll();
$option .= '<option value="" disabled selected >SELECT BANK</option>';
foreach ($dataBank as $value) {
$option .= "<option value=".$value['bankID'].">".$value['bankName']."</option>";
}
echo $option;
}
?>
并尝试将此选项绑定到您选择的银行ID
$('#fiid').html(dataBank);