堆栈溢出
如何获取itemView计数。我想对ListView中的每三个项目做一些事情。
echo ListView::widget([
'dataProvider' => $modelDataProvider,
'itemView' => '_item_view',
'viewParams' => [
'count' => $itemcount // How to get this variable?
],
])
// _item_view.php
if($count % 3 == 0) {
// this item is the third in a row, do something special
}
感谢您的帮助!
找到了答案。Yii2的ListView
自己注入$index
参数。
您可以在itemView中使用该参数。