本文的方法实现一级联下拉菜单的详细描述。以下步骤如下:

下面的代码添加到1。模板:


< PHP
echo $表-> DropDownList(元模型,'src_type_id ',ordersrc::选项()),数组(
ID = > 'task-order-src-id,
));
echo $表-> DropDownList(元模型,'src_shop_id,阵列(= >,阵列(所有)
ID = > 'task-shop-id,
))
>




在这段代码中,ordersrc_options()这是读一个下拉菜单第一。请orderscr模型选择方法,内容如下


公共静态功能选项($ hasshop = true){
新的自我();
如果美元(美元hasshop)模型-> hasshop();
美元=美元->所有模型模型();
$array =阵列(= > 'all');
foreach(元模型达模型){
数组$ { $模型-> src_id } = $模型-> src_name;
}
返回数组;
}




2。然后,在第一个下拉菜单更改时,将JS代码添加到模板页,以实现对第二下拉菜单的内容分配。



$()Ready(函数(e){)
$(#任务顺序SRC ID)。变化(功能(e){
refreshshops();
});
refreshshops();
功能refreshshops(){
$.get ('createUrl ('getShops')', {
srcid:$(' #任务顺序SRC ID)瓦迩()。
},功能(html_content){
$(#任务店ID)
HTML(html_content)。
找到('option {价值= src_shop_id > })
.attr(选中,选中的);
});
}
});





在这个JS代码,程序检索得到第二下拉菜单的值(在控制器调用actiongetshops法),并将它添加到第二下拉菜单。

在控制器的actiongetshops方法如下:


公共功能actiongetshops(){
srcid美元美元'srcid_get { } =;
$array = thirdpartinterfaceconfig::选项($ srcid);
htmlcontent美元= ;
foreach(数组$ K = > $ V){
htmlcontent美元={ $ V };
}
echo $ htmlcontent;
}