我想编辑所选的框,但在我有编辑按钮的情况下不显示它。
这是我对javascript的看法:
<script type="text/javascript">
function edit(id) {
$('#form-edit').remove();
$.ajax({
type: 'POST',
data: '',
url: '<?php echo site_url("pangkat/edit")?>/' + id,
success: function(data) {
obj = JSON.parse(data);
var html = '' +
'<form id="form-edit">' +
'<div class="form-group">' +
'<label class="control-label labelnya"><i class="ion ion-home"></i>Golongan:</label>' +
'<select class="persons" name="id_golongan" style="width: 100%" data-placeholder="Pilih Golongan">' +
'<option></option>' +
<?php foreach($golongan as $val) {
if ($val['ID_GOLONGAN'] == $id_golongan)
echo '<option value="'.$val['ID_GOLONGAN'].'" selected>'.$val['GOLONGAN'].'</option>';
else
echo '<option value="'.$val['ID_GOLONGAN'].'">'.$val['GOLONGAN'].'</option>';
}?>
'</select>' +
'</div>' +
'</form>';
}
});
}
</script>`
这是我的控制器:
public function edit($id = NULL)
{
// $data['golongan'] = $this->M_golongan->get();
$data = $this->M_pangkat->get($id);
echo json_encode(array(
'id_pangkat' =>$data['ID_KENAIKAN_PANGKAT'],
'id_pegawai' =>$data['ID_PEGAWAI'],
'id_golongan' =>$data['ID_GOLONGAN'],
'sk_pangkat' =>$data['SK_PANGKAT'],
'tgl_mulai' =>date('d-m-Y ',strtotime($data['TGL_MULAI'])),
'tgl_terhitung' =>date('d-m-Y ',strtotime($data['TGL_TERHITUNG']))
));
}