Yii2。同一页面中有多个pjax。第二个不工作的权利

问题描述 投票:0回答:1

对不起,我的英语刚开始!

我对pjax有问题。可以在一页中多次使用吗?我尝试在页面上的两个地方使用相同的pjax块。块具有不同的ID。第二个块无法正常工作:页面需要刷新!

它的工作方式类似于yii2-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(); ?>

等待您的注意!谢谢!

php yii yii2 pjax
1个回答
0
投票

如果要在一页中使用两个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(); ?>
© www.soinside.com 2019 - 2024. All rights reserved.