Yii2.多个pjax在同一个页面.第二个不能正常工作

4sup72z8  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(170)

对不起,我的英语第一!
我的pjax有问题。它可以在一个页面中使用多个吗?我尝试在页面的两个地方使用相同的pjax块。块有不同的id。第二个块不工作的权利:页面正在刷新!
它像yii 2-widget一样工作。Widget在页面上启动两次!
我的代码:

public function run()
   {
      $id_performer = $this->id_performer;
      $id_city = $this->id_city;
      $QueryItems = City::getItemsByPerformer($id_performer, $id_city);

      $countQuery = clone $QueryItems;
      $allCount = $countQuery->count();

      $haveMoreButton = \Yii::$app->params['perPage'] < $allCount;

      $items = $QueryItems->limit(\Yii::$app->params['perPage'])->all();
      return $this->render('items_widget', compact('items', 'haveMoreButton', 'id_performer', 'id_city'));
   }

和一般视图文件:

<?php  $pjax = Pjax::begin(['enablePushState' => false, 'timeout' => false]);
$pjaxId = $pjax->getId();
$pjax->linkSelector = '#link' . $pjaxId;
?>
<?php if (!empty($items)) : ?>
      <?php foreach ($items as $item): ?>
         <?php include __DIR__ . '/../catalog-item.php'; ?>
      <?php endforeach; ?>
      <?php if (isset($haveMoreButton) && $haveMoreButton): ?>
         <div>
            <?= Html::a('Show More', ['/site/pjax-news', 'limit' => (isset($limit) ? $limit : (\Yii::$app->params['perPage'] * 2)), 'id_performer' => (isset($id_performer) ? $id_performer : 0),'id_city' => (isset($id_city) ? $id_city : 0)],
               ['class' => 'btn big dark button_show_more', 'id' => 'link' . $pjaxId, 'data-pjax' => 1]); ?>
         </div>
      <?php endif; ?>
<?php endif; ?>
<?php Pjax::end(); ?>

等待你们的思想!谢谢!

des4xlb0

des4xlb01#

如果你想在一个页面中使用两个pjax,你可以按如下方式操作:

Pjax::begin([
 'id' => 'id1',
 'enablePushState' => false,
]); ?>
 //write your code here
 <?php Pjax::end(); ?>
Pjax::begin([
 'id' => 'id2',
 'enablePushState' => false,
]); ?>
 //write another code here
 <?php Pjax::end(); ?>

相关问题