$.fn.yiiListView.update doesn't update ClistVi

2019-07-15 10:56发布

问题:

I'm trying to update my ClistView in Yii 1.1.15, using $.fn.yiiListView.update. I do get it to echo the proper results back, but it doesn't update the list.

in my JS

var ajaxRequest = "lat="+position.coords.latitude+"&lng="+position.coords.longitude;
$.fn.yiiListView.update("store-list", {data:ajaxRequest});

in my actionIndex()

if ($_GET['ajax']==='store-list') {
            $sql = "SELECT * FROM ........ ";
            $count=Yii::app()->db->createCommand('SELECT COUNT(*) FROM `store` WHERE `pending`!="1"')->queryScalar();
            //echo $query;
            $dataProvider=new CSqlDataProvider($sql, array(
                                                    'params'=> array(':lat' => $lat, ':lng'=>$lng, ':radius'=>$radius),
                                                    'totalItemCount'=>$count,
                                                    'sort'=>array(
                                                        'attributes'=>array(
                                                             'store', 'state', 'distance',
                                                        ),
                                                    ),
                                                    'pagination'=>false
                                                )
                                            );
            //render page
            $this->renderPartial('_store-list',array(
                    'dataProvider'=>$dataProvider,
            ));
        }

in my view, index.php i call _store-list.php like this

<div class="padding-top-20px">
            <?php $this->renderPartial('_store-list', array("dataProvider"=>$dataProvider)); ?>
</div>

in my _store-list.php i have this

<?php 
        $this->widget('zii.widgets.CListView', array(
            'id' => 'store-list',
            'dataProvider'=>$dataProvider,
            'itemView'=>'_view',
            'pagerCssClass' => 'pagination',
            'ajaxUpdate'=>false, //disable ajax sort and pagination
            'loadingCssClass' => '', //remove loading icon
            'sortableAttributes'=>array(
                'dealership' => 'Store',
                'state' => 'State',
                'distance' => 'Distance'
            ),
        )); ?>

any idea's why it doesnt update the clistview?

UDPATED:

narrowed it down to this. in my jquery.yiilistview.js the each loop fails. tried manually setting the ajaxUpdate variable liks this. but still failed. in debug ajaxUpdate is still empty. any ideas?

in my JS:

 $.fn.yiiListView.update("store-list", {ajaxUpdate:"store-list", data:ajaxRequest});

in jquery.yiilistview.js:

success: function(data,status) {
                console.debug(settings);
                $.each(settings.ajaxUpdate, function(i,v) {
                    $(id).replaceWith($(id,'<div>'+data+'</div>'));
                });
                if(settings.afterAjaxUpdate != undefined)
                    settings.afterAjaxUpdate(id, data);
            },

回答1:

solved it. For some reason had to download Yii 1.1.15 again. something broke i guess.

$.fn.yiiListView.update("store-list", { data:ajaxRequest });

works fine now.



标签: php yii