如何在 yii2 中刷新 pjax 列表视图?它重新加载整个页面 [英] How to refresh pjax listview in yii2? It reloads the entire page

查看:41
本文介绍了如何在 yii2 中刷新 pjax 列表视图?它重新加载整个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在不刷新整个页面的情况下刷新 pjax 列表视图.这是 pjax 列表本身的视图.

I want to be able to refresh a pjax listview without refreshing the whole page. This is the view just the pjax list itself.

<?= Html::Button('refresh-countries', ['class' => 'btn btn-primary', 'name' => 'login-button', 'id'=>'refresh']) ?>  

<?php Pjax::begin(['id' => 'countries']) ?>

    <?= ListView::widget([
         'dataProvider' => $dataProvider,
         'itemOptions'  => ['class' => 'comment-item'],
         'itemView'     => 'commentadapter',

    ]); ?> 

<?php Pjax::end() ?>

请我希望它在单击该按钮时刷新,并且只有列表视图会刷新.我知道怎么做,但它会刷新整个页面.

Please I want it to refresh onclick of that button and only the listview would refresh. I know how to do it but it refreshes the whole page.

推荐答案

你必须喜欢这个:

 use yii\widgets\Pjax;

<?php Pjax::begin(['id' => 'some_pjax_id']) ?>
     //your code 
 <?php Pjax::end() ?>

上面包含在选项卡中的表单,这里是我重新加载 pjax 的脚本:

above form contained in tab and here is my script to reload pjax :

$("#my_tab_id").click(function() {
    $.pjax.reload({container: '#some_pjax_id', async: false});
});

这篇关于如何在 yii2 中刷新 pjax 列表视图?它重新加载整个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆