search
Homephp教程php手册yii实现级联下拉菜单的方法

这篇文章主要介绍了yii实现级联下拉菜单的方法,需要的朋友可以参考下

本文详细讲述了yii实现级联下拉菜单的方法,具体步骤如下:

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 = ""; } echo $htmlContent; }

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment