Anonymous
Получить значение из json и поместить в раскрывающийся список
Сообщение
Anonymous » 27 дек 2025, 11:56
form.php
Код: Выделить всё
array(
gettext('Gateway Name'),
array(
"name" => "gateway_id",
"class" => "gateway_id",
"id" => "gateway_id"
),
'SELECT',
'',
'trim|required|xss_clean',
'tOOL TIP',
'Please select gateway first',
'id',
'name',
'gateways',
'build_dropdown',
'where_arr',
array(
"status" => "0"
)
),
view.php
Код: Выделить всё
$(".gateway_routing_type").change(function(){
var gateway_routing_type =$('.gateway_routing_type option:selected').val();
$.ajax({
type:'POST',
url: "/trunk/trunk_sipdevicelist/",
data:"gateway_routing_type="+gateway_routing_type,
success: function(response) {
var tmp = jQuery.parseJSON(response);
console.log(response);
$("#gateway_id").empty();
$.each(tmp, function(key, value) {
$("#gateway_id").append($('').val(value.id).html(value.name));
});
$(".selectpicker").selectpicker('refresh');
}
});
});
controller.php
Код: Выделить всё
$add_array = $this->input->post();
$gateway_routing_type = $add_array['gateway_routing_type'];
$accountinfo = $this->session->userdata("accountinfo");
$gateway_array = array();
if ($gateway_routing_type == "0") {
$gateway_result = $this->db->get_where('gateways', array(
"gateway_routing_type" => $gateway_routing_type,
"status" => 0
));
if ($gateway_result->num_rows() > 0) {
$gateway_result = $gateway_result->result_array();
foreach ($gateway_result as $key => $value) {
$gateway_array[] = array(
"id" => $value['id'],
"name" => $value['name']
);
}
}
} else {
$this->db->select('GROUP_CONCAT(id) as provider_id');
$provider_id = (array)$this->db->get_where("accounts", array( "status" => 0, "deleted" => 0, "type" => 3))->first_row();
$array = explode(",", $provider_id['provider_id']);
foreach ($array as $value) {
$sipdevice_result = $this->db->get_where("sip_devices", array("accountid" => $value));
if ($sipdevice_result->num_rows() > 0) {
$sipdevice_result = $sipdevice_result->result_array();
foreach ($sipdevice_result as $key => $value) {
$gateway_array[] = array(
"id" => $value['id'],
"name" => $value['username']
);
}
}
}
}
когда происходит вызов ajax, он переходит к функции и отображает выбранное раскрывающееся значение.
Подробнее здесь:
https://stackoverflow.com/questions/628 ... o-dropdown
1766825795
Anonymous
form.php [code]array( gettext('Gateway Name'), array( "name" => "gateway_id", "class" => "gateway_id", "id" => "gateway_id" ), 'SELECT', '', 'trim|required|xss_clean', 'tOOL TIP', 'Please select gateway first', 'id', 'name', 'gateways', 'build_dropdown', 'where_arr', array( "status" => "0" ) ), [/code] view.php [code]$(".gateway_routing_type").change(function(){ var gateway_routing_type =$('.gateway_routing_type option:selected').val(); $.ajax({ type:'POST', url: "/trunk/trunk_sipdevicelist/", data:"gateway_routing_type="+gateway_routing_type, success: function(response) { var tmp = jQuery.parseJSON(response); console.log(response); $("#gateway_id").empty(); $.each(tmp, function(key, value) { $("#gateway_id").append($('').val(value.id).html(value.name)); }); $(".selectpicker").selectpicker('refresh'); } }); }); [/code] controller.php [code]$add_array = $this->input->post(); $gateway_routing_type = $add_array['gateway_routing_type']; $accountinfo = $this->session->userdata("accountinfo"); $gateway_array = array(); if ($gateway_routing_type == "0") { $gateway_result = $this->db->get_where('gateways', array( "gateway_routing_type" => $gateway_routing_type, "status" => 0 )); if ($gateway_result->num_rows() > 0) { $gateway_result = $gateway_result->result_array(); foreach ($gateway_result as $key => $value) { $gateway_array[] = array( "id" => $value['id'], "name" => $value['name'] ); } } } else { $this->db->select('GROUP_CONCAT(id) as provider_id'); $provider_id = (array)$this->db->get_where("accounts", array( "status" => 0, "deleted" => 0, "type" => 3))->first_row(); $array = explode(",", $provider_id['provider_id']); foreach ($array as $value) { $sipdevice_result = $this->db->get_where("sip_devices", array("accountid" => $value)); if ($sipdevice_result->num_rows() > 0) { $sipdevice_result = $sipdevice_result->result_array(); foreach ($sipdevice_result as $key => $value) { $gateway_array[] = array( "id" => $value['id'], "name" => $value['username'] ); } } } } [/code] когда происходит вызов ajax, он переходит к функции и отображает выбранное раскрывающееся значение. Подробнее здесь: [url]https://stackoverflow.com/questions/62801235/get-value-from-the-json-and-put-into-dropdown[/url]