嘿朋友们,我正在尝试制作两个下拉框。第一个是传感器类型选择。第二个是传感器名称,它应该取决于第一个。我正在使用 MVC 架构。这是我正在使用的代码。在 viewpage.php 我有:
<table>
<td>
<label><b>Sensors Types:</b></label>
</td>
<td>
<?php echo form_dropdown('sensor_types', $sensor_types, '#', 'id="sensor_types" onchange="copy();" ');?>
</td>
<td> </td>
<td> </td>
<td>
<label><b>Sensor Name:</b></label>
</td>
<td>
<?php echo form_dropdown('sensorzs', $sensorzs, '#', 'id="sensorzs"'); ?>
</td>
</tr>
</table>
model.php 中的代码是
function sensors_list($node_id) {
$this->db->select('sensor_index, sensor_name');
$this->db->where('node_id', $node_id);
//$this->db->where('sensor_type', $sensor_types);
$this->db->order_by('sensor_index');
$query = $this->db->get('node_sensor_dtl');
}
function get_all_sensors($node_id) {
$this->db->select('sensor_pk, sensor_name');
$this->db->where('node_id', $node_id);
$this->db->order_by('sensor_index');
$query = $this->db->get('node_sensor_dtl');
$sensors = array();
if($query->result())
{
$sensors[''] = '-Select-';
foreach ($query->result() as $sensor)
{
$sensors[$sensor->sensor_pk] = $sensor->sensor_name;
}
return $sensors;
}
else {
$sensors = NULL;
return $sensors;
}
}
而node.php中的代码代码是这样的
function edit(){
if($this->CI->input->post('editform_id') == NULL) redirect('configuration/node/');
$view_data['page_title'] = "Node edit details";
$view_data['page_name'] = "";
$view_data['detail'] = $this->CI->model->get_node($this->CI->input->post('editform_id'));
$view_data['sensor_types'] = $this->CI->model->get_all_sensor_types();
$view_data['sensorzs'] = $this->CI->model->sensors_list($this->CI->input->post('editform_id'));
$this->CI->load->view('config_node_view', $view_data);
}
过去几天我已经尝试过这个,但可以得到结果。搜索了很多网站和博客,但我无法获得所需的结果。