Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php fn.yiiGridView.update事件未触发_Php_Ajax_Yii - Fatal编程技术网

Php fn.yiiGridView.update事件未触发

Php fn.yiiGridView.update事件未触发,php,ajax,yii,Php,Ajax,Yii,我是Yii的新手。我有一个下拉列表和一个CGridView。我的想法是,我想根据用户在下拉列表中选择的内容过滤gridview中显示的记录。我读过几本教程,几乎所有的都很像 不幸的是,代码似乎没有触发gridview更新事件 这是我基于教程的代码 控制器 public function actionIndex() { $criteria = (isset($_GET['id-dropdown'])) ? array(

我是Yii的新手。我有一个下拉列表和一个CGridView。我的想法是,我想根据用户在下拉列表中选择的内容过滤gridview中显示的记录。我读过几本教程,几乎所有的都很像

不幸的是,代码似乎没有触发gridview更新事件

这是我基于教程的代码

控制器

public function actionIndex()
{

        $criteria = (isset($_GET['id-dropdown'])) ?
                array(
                    'condition' => 'account = ' . $_GET['id-dropdown'],
                ): array();

        $options = array(
            'criteria' =>$criteria,
            'pagination' => array(
                'pagesize' => 100,
            ),
        );
        $modelAccount = new Account();
        $dataProvider = new CActiveDataProvider('Jurnal', $options);

        $selected_account = (isset($_GET['id-dropdown'])) ? $_GET['id-dropdown']: '101'; //101 is the default

    $this->render('index', array(
                //'modelCustom'=>$modelCustom,
'modelAccount'=>$modelAccount, 
                'dataProvider'=>$dataProvider,
                'selected_account' => $selected_account ));
}
这是我的看法

   <?php 
Yii::app()->clientScript->registerScript('items_update', "$('#id-dropdown').change(function(){
        alert('ok'); //this works
        $.fn.yiiGridView.update('jurnal-grid', {
                type:'GET',
                data: $(this).serialize(),
                success=>
                   js:function() { $.fn.yiiGridView.update('jurnal-grid');}
                }
            }
        );
    });
    return false;",
    CClientScript::POS_READY);
?>
<h1>View Per Account</h1>
<div class="form">
<?php

$form=$this->beginWidget('CActiveForm', array(
    'id'=>'menu-dropdown-form',
    'enableAjaxValidation'=>true,
));

echo $form->labelEx($modelAccount, $selected_account);
$criteria = new CDbCriteria();
$criteria->order = 'id ASC';
$account = Account::model()->findAll($criteria);
$accountlist = CHtml::listData($account, 'id', 'description');
echo CHtml::dropDownList('id-dropdown', '$selected_account', $accountlist);
$this->endWidget();

?>
</div>
<?php
$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'jurnal-grid',
    'dataProvider'=>$dataProvider,
    'columns' => array(
        'tanggal',
        'account',
        array(
            'class' => 'CButtonColumn',
        ),
    ),
));
?>
尝试替换

success=>
    js:function() { $.fn.yiiGridView.update('jurnal-grid');}

无需使用
js:function

代替此:

$.fn.yiiGridView.update('jurnal-grid', {
    type:'GET',
    data: $(this).serialize(),
    success=>
        js:function() { $.fn.yiiGridView.update('jurnal-grid');}
    }
});
试试这个:

$.fn.yiiGridView.update('jurnal-grid', {
    data: $(this).serialize()
});

我认为您的js中有错误,这里是
success=>js:function(){$.fn.yiiGridView.update('jurnal-grid');}}
$.fn.yiiGridView.update('jurnal-grid', {
    data: $(this).serialize()
});