茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    Yii2使用dropdownlist實(shí)現(xiàn)地區(qū)三級(jí)聯(lián)動(dòng)功能的方法
    來(lái)源:易賢網(wǎng) 閱讀:1025 次 日期:2016-08-12 15:18:55
    溫馨提示:易賢網(wǎng)小編為您整理了“Yii2使用dropdownlist實(shí)現(xiàn)地區(qū)三級(jí)聯(lián)動(dòng)功能的方法”,方便廣大網(wǎng)友查閱!

    本文實(shí)例講述了Yii2使用dropdownlist實(shí)現(xiàn)地區(qū)三級(jí)聯(lián)動(dòng)功能的方法。分享給大家供大家參考,具體如下:

    視圖部分:

    <?php

    use yii\helpers\Url;

    use yii\widgets\ActiveForm;

    use yii\helpers\ArrayHelper;

    use yii\helpers\Html;

    /* @var $this yii\web\View */

    /* @var $model common\search\service\ItemSearch */

    /* @var $form yii\widgets\ActiveForm */

    ?>

    <div class="row">

      <div class="item-search">

        <?php $form = ActiveForm::begin([

          'action' => ['index'],

          'method' => 'get',

          'options' => ['class' => 'form-inline']

        ]); ?>

        <?= $form->field($model, 'cityName', ['options' => ['class' => 'form-group col-lg-2']])->dropDownList(ArrayHelper::map($cities, 'id', 'name'), ['prompt' => '請(qǐng)選擇城市'])->label('請(qǐng)選擇城市', ['class' => 'sr-only']) ?>

        <?= $form->field($model, 'areaName', ['options' => ['class' => 'form-group col-lg-2']])->dropDownList(ArrayHelper::map($areas, 'id', 'name'), ['prompt' => '請(qǐng)選擇區(qū)縣'])->label('請(qǐng)選擇區(qū)縣', ['class' => 'sr-only']) ?>

        <?= $form->field($model, 'communityName', ['options' => ['class' => 'form-group col-lg-2']])->dropDownList(ArrayHelper::map($communities, 'id', 'name'), ['prompt' => '請(qǐng)選擇小區(qū)'])->label('請(qǐng)選擇小區(qū)', ['class' => 'sr-only']) ?>

        <div class="col-lg-2 col-lg-offset-1">

          <input class="form-control" id="keyword" placeholder="請(qǐng)輸入小區(qū)名" value="" />

        </div>

        <div class="col-lg-1">

          <button type="button" id="search-community" class="btn btn-info">搜索</button>

        </div>

        <p></p>

        <div class="form-group col-lg-1 pull-right">

          <?= Html::submitButton('搜索', ['class' => 'btn btn-primary']) ?>

        </div>

        <?php ActiveForm::end(); ?>

      </div>

    </div>

    <p> </p>

    <?php

    $this->registerJs('

      //市地址改變

      $("#itemsearch-cityname").change(function() {

        //市id值

        var cityid = $(this).val();

        $("#itemsearch-areaname").html("<option value=\"0\">請(qǐng)選擇區(qū)縣</option>");

        $("#itemsearch-communityname").html("<option value=\"0\">請(qǐng)選擇小區(qū)</option>");

        if (cityid > 0) {

          getArea(cityid);

        }

      });

      //區(qū)地址改變

      $("#itemsearch-areaname").change(function() {

        //區(qū)id值

        var areaid = $(this).val();

        $("#itemsearch-communityname").html("<option value=\"0\">請(qǐng)選擇小區(qū)</option>");

        if (areaid > 0) {

          getCommunity(areaid);

        }

      });

      //獲取市下面的區(qū)列表

      function getArea(id)

      {

        var href = "' . Url::to(['/service/base/get-area-list'], true). '";

        $.ajax({

          "type" : "GET",

          "url"  : href,

          "data" : {id : id},

          success : function(d) {

            $("#itemsearch-areaname").append(d);

          }

        });

      }

      //獲取區(qū)下面的小區(qū)列表

      function getCommunity(id)

      {

        var href = "' . Url::to(['/service/base/get-community-list'], true) . '";

        $.ajax({

          "type" : "GET",

          "url"  : href,

          "data" : {id : id},

          success : function(d) {

            $("#itemsearch-communityname").append(d);

          }

        });

      }

      //搜索小區(qū)

      $("#search-community").click(function() {

        var word  = $("#keyword").val();

        var areaid = $("#itemsearch-areaname option:selected").val();

        var href  = "' . Url::to(['/service/base/search-community'], true) . '";

        if (areaid > 0) {

          $.ajax({

            "type" : "GET",

            "url"  : href,

            "data" : {id : areaid, word : word},

            success : function(d) {

              $("#itemsearch-communityname").html(d);

            }

          });

        }

      });

    ');

    ?>

    模型部分:

    就是我們常用的ajax請(qǐng)求,當(dāng)然php中需要直接組合成<option value=""></option>這樣的結(jié)構(gòu)直接用,$form->field($model, $var)中的變量數(shù)據(jù)表中不一定有,得在模型中自己定義,并設(shè)置安全字段,而且搜索模型也可能需要修改成自己需要的樣子,模型可能要這樣:

    class HuangYeError extends \yii\db\ActiveRecord

    {

      public $cityName;

      public $areaName;

      public $communityName;

      public $group;

      public $cate;

      /**

       * @inheritdoc

       */

      public static function tableName()

      {

        return 'll_hy_huangye_error';

      }

      public static function getDb()

      {

        return Yii::$app->get('dbnhuangye');

      }

    }

    之前是多表,需要使用jjoinWith()連表,后來(lái)被我全部轉(zhuǎn)化為單表了,多表實(shí)在是慢,能轉(zhuǎn)化成單表就用單表吧:

    class HuangYeErrorSearch extends HuangYeError

    {

      const PAGE_SIZE = 20;

      public $communityName;

      public $startTime;

      public $endTime;

      /**

       * @inheritdoc

       */

      public function rules()

      {

        return [

          [['id', 'serviceid', 'userid', 'categoryid', 'communityid', 'sortorder', 'ctime', 'utime', 'status'], 'integer'],

          [['username', 'name', 'logo', 'phone', 'address', 'content', 'error', 'communityName', 'startTime', 'endTime'], 'safe'],

        ];

      }

      /**

       * @inheritdoc

       */

      public function scenarios()

      {

        // bypass scenarios() implementation in the parent class

        return Model::scenarios();

      }

      /**

       * Creates data provider instance with search query applied

       *

       * @param array $params

       *

       * @return ActiveDataProvider

       */

      public function search($params)

      {

        $query = HuangYeError::find();

        //status == 9 刪除狀態(tài)

        $condition = ' `status` != :status';

        $p[':status'] = 9;

        $query->where($condition, $p);

        $dataProvider = new ActiveDataProvider([

          'query' => $query,

          'pagination' => [

            'pageSize' => self::PAGE_SIZE,

          ],

        ]);

        $this->load($params);

        if (!$this->validate()) {

          // uncomment the following line if you do not want to any records when validation fails

          // $query->where('0=1');

          return $dataProvider;

        }

        $query->andFilterWhere([

          'userid' => $this->userid

        ]);

        $query->andFilterWhere(['like', 'username', $this->username])

          ->andFilterWhere(['like', 'name', $this->name])

          ->andFilterWhere(['like', 'phone', $this->phone])

          ->andFilterWhere(['like', 'address', $this->address])

          ->andFilterWhere(['like', 'content', $this->content])

          ->andFilterWhere(['ll_hy_huangye_error.status' => $this->status])

          ->andFilterWhere(['ll_hy_huangye_error.categoryid' => $this->categoryid])

          ->andFilterWhere(['between', 'ctime', strtotime($this->startTime . '0:0:0'), strtotime($this->endTime . '23:59:59')])

          ->andFilterWhere(['like', 'error', $this->error]);

        if (intval($this->communityName)) {

          $query->andFilterWhere(['ll_hy_huangye_error.communityid' => intval($this->communityName)]);

        }

        $order = ' `ctime` DESC';

        $query->orderBy($order);

        return $dataProvider;

      }

    }

    控制器中寫比較簡(jiǎn)單一點(diǎn),直接調(diào)用就行了:

    /**

    * ajax請(qǐng)求小區(qū)

    *

    * @param $id

    * @return string

    */

    public function actionGetCommunityList($id)

    {

        $option = '';

        $result = self::getCommunity($id);

        if ($result) {

          foreach ($result as $value) {

            $option .= '<option value="' . $value['id'] . '">' . $value['name'] . '</option>';

          }

        } else {

          $option .= '<option value="0">暫未開(kāi)通可選擇的小區(qū)</option>';

        }

        echo $option;

    }

    希望本文所述對(duì)大家基于Yii框架的PHP程序設(shè)計(jì)有所幫助。

    更多信息請(qǐng)查看網(wǎng)絡(luò)編程
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2026上岸·考公考編培訓(xùn)報(bào)班

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)