1.模版中加入如下代码:
dropdownlist($model, 'src_type_id', ordersrc::options(), array( 'id' => 'task-order-src-id', )); echo $form->dropdownlist($model, 'src_shop_id', array(''=>'全部'), array( 'id' => 'task-shop-id', ))?>
在这段代码中,ordersrc_options() 这个是先读取一个下拉菜单。调用orderscr model中的options方法。内容如下
public static function options($hasshop = true) { $model = new self(); if($hasshop) $model->hasshop(); $models = $model->findall(); $array = array(''=>'全部'); foreach($models as $model) { $array[$model->src_id] = $model->src_name; } return $array;}
2.然后在模版页面中增加js代码,实现当第一个下拉菜单变化时给第二个下拉菜单进行内容赋值。
在这段js代码中,实现调取一个程序获取第二个下拉菜单的值(调用controller中的actiongetshops方法),任何追加到第二个下拉菜单中。
controller中的actiongetshops方法如下:
public function actiongetshops() { $srcid = $_get['srcid']; $array = thirdpartinterfaceconfig::options($srcid); $htmlcontent = 全部; foreach($array as $k=>$v) { $htmlcontent .= {$v}; } echo $htmlcontent;}
