Skip to content

Commit 567ecb9

Browse files
committed
Refactor ListRenderer for support yield
1 parent 1e5c898 commit 567ecb9

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Yii2 multiple input change log
44
2.18.0 (in development)
55
=======================
66
- #246 accept `\Traversable` in model attribute for `yield` compatibility (bscheshirwork)
7-
- #250 accept `\Traversable` in TableRenderer for `yield` compatibility (bscheshirwork)
7+
- #250 accept `\Traversable` in TableRenderer and ListRenderer for `yield` compatibility (bscheshirwork)
88

99
2.17.0
1010
======

src/renderers/ListRenderer.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,16 @@ protected function renderBody()
105105
$rows = [];
106106

107107
if ($this->data) {
108-
$cnt = count($this->data);
109-
if ($this->min === $this->max && $cnt < $this->max) {
110-
$cnt = $this->max;
108+
$j = 0;
109+
foreach ($this->data as $index => $item) {
110+
if ($j++ <= $this->max) {
111+
$rows[] = $this->renderRowContent($index, $item);
112+
} else {
113+
break;
114+
}
111115
}
112-
113-
$indices = array_keys($this->data);
114-
115-
for ($i = 0; $i < $cnt; $i++) {
116-
$index = ArrayHelper::getValue($indices, $i, $i);
117-
$item = ArrayHelper::getValue($this->data, $index, null);
118-
$rows[] = $this->renderRowContent($index, $item);
116+
for ($i = $j; $i < $this->min; $i++) {
117+
$rows[] = $this->renderRowContent($i);
119118
}
120119
} elseif ($this->min > 0) {
121120
for ($i = 0; $i < $this->min; $i++) {

0 commit comments

Comments
 (0)