我想问。我也有问题,无法从详细产品中获取ID并将其传递给控制器,而我的第一次尝试显示了[object Object] $ abc123。如何使从对象对象到字符串[对象对象] $ abc123变为仅$ abc123?我也想让我的select2仅显示仅适用于产品abc123的uom。
这是我的源代码JS。
$("#selUom").select2({
ajax: {
url: '<?=base_url("transaksi/get/uom")?>',
type: "post",
dataType: 'json',
data: function(params) {
return {
idprod: params+'<?php echo $detprod["productcode"]; ?>',
searchTerm: params.term // search term
};
},
processResults: function(response) {
return {
results: response
};
},
cache: true
}
});
控制器
public function allUom(){
$searchTerm = $this->input->post('searchTerm');
$idprod = $this->input->post('idprod');
$response = $this->M_Mstuom->allBasedUom($idprod,$searchTerm);
echo json_encode($response);
}
型号
public function allBasedUom($id, $searchTerm=""){
$this->db->select('m.uomid, m.uom');
$this->db->join("msuom m", "m.uomid = pu.uomid");
$this->db->where("m.uom like '%" . $searchTerm . "%' ");
$this->db->where("pu.productcode", $id);
$this->db->where("m.isactive", "t");
$fetched_records = $this->db->get('msproductuom pu');
$uom = $fetched_records->result_array();
$data = array();
foreach ($uom as $uom) {
$data[] = array("id" => $uom['uomid'], "text" => $uom['uom']);
}
return $data;
}
Try to use :
$("#selUom").select2({
ajax: {
url: '<?=base_url("transaksi/get/uom")?>',
type: "post",
dataType: 'json',
data: function(params) {
return {
idprod: params.'<?php echo $detprod["productcode"]; ?>',
searchTerm: params.term // search term
};
},
processResults: function(response) {
return {
results: response
};
},
cache: true
}
});