<?php echo $form->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; }
<script type='text/javascript'> $().ready(function(e) { $('#task-order-src-id').change(function(e) { refreshShops(); }); refreshShops(); function refreshShops() { $.get('<?php echo $this->createUrl('getShops')?>', { 'srcId': $('#task-order-src-id').val() }, function(html_content) { $('#task-shop-id') .html(html_content) .find('option[value=<?php echo $model->src_shop_id?>]') .attr('selected', 'selected'); }); } }); </script>
public function actionGetShops() { $srcId = $_GET['srcId']; $array = ThirdpartInterfaceConfig::options($srcId); $htmlContent = "<option value=''>全部</options>"; foreach($array as $k=>$v) { $htmlContent .= "<option value='{$k}'>{$v}</option>"; } echo $htmlContent; }