下拉菜单级联查询 不能触发ajax…… [ 新手入门 ]
如题,请教 代码如下: _form中
<?php
echo $form->dropDownlist($channel, 'channel_parent_id', Channel::channels(),
array(
'ajax' => array(
'type' => 'POST', //request type
'url' => Yii::app()->createUrl('Channel/Dynamiccities'),
'update' => '#Channel[channel_id]', //selector to update
//'data'=>'js:javascript statement'
//leave out the data key to pass all form values through
)));
echo CHtml::dropDownList('Channel[channel_id]', '', array("请先选择国家")); ?>
Channelcontroller中:
public function actionDynamiccities() {
$parent_id = (int) $_POST['Channel']['channel_parent_id'];
$data = Location::model()->findAll('channel_parent_id=:parent_id',
array(':parent_id' => $parent_id));
if (!isset($data))
$data = array(
array("id" => 0, "name" => "请先选择国家"),
);
$data = CHtml::listData($data, 'id', 'name');
foreach ($data as $value => $name) {
echo CHtml::tag('option',
array('value' => $value), CHtml::encode($name), true);
}
}
共 0 条回复
没有找到数据。
tz_com 山东
注册时间:2011-03-01
最后登录:2019-08-18
在线时长:1小时9分
最后登录:2019-08-18
在线时长:1小时9分
- 粉丝1
- 金钱440
- 威望0
- 积分450