yunfeng0614

yunfeng0614

这家伙有点懒,还没写个性签名!

  • 财富值15
  • 威望值0
  • 总积分55

个人信息

  • 2019-04-03 已签到
    连续签到1天,获得了5个金钱
  • 回复了 的回答

    参照yii\grid\GridView的这两个方法

    public function renderTableBody()
        {
            $models = array_values($this->dataProvider->getModels());
            $keys = $this->dataProvider->getKeys();
            $rows = [];
            foreach ($models as $index => $model) {
                $key = $keys[$index];
                if ($this->beforeRow !== null) {
                    $row = call_user_func($this->beforeRow, $model, $key, $index, $this);
                    if (!empty($row)) {
                        $rows[] = $row;
                    }
                }
    
                $rows[] = $this->renderTableRow($model, $key, $index);
    
                if ($this->afterRow !== null) {
                    $row = call_user_func($this->afterRow, $model, $key, $index, $this);
                    if (!empty($row)) {
                        $rows[] = $row;
                    }
                }
            }
    
            if (empty($rows)) {
                $colspan = count($this->columns);
    
                return "<tbody>\n<tr><td colspan=\"$colspan\">" . $this->renderEmpty() . "</td></tr>\n</tbody>";
            } else {
                return "<tbody>\n" . implode("\n", $rows) . "\n</tbody>";
            }
        }
    
    public function renderTableRow($model, $key, $index)
        {
            $cells = [];
            /* @var $column Column */
            foreach ($this->columns as $column) {
                $cells[] = $column->renderDataCell($model, $key, $index);
            }
            if ($this->rowOptions instanceof Closure) {
                $options = call_user_func($this->rowOptions, $model, $key, $index, $this);
            } else {
                $options = $this->rowOptions;
            }
            $options['data-key'] = is_array($key) ? json_encode($key) : (string) $key;
    
            return Html::tag('tr', implode('', $cells), $options);
        }
    

    正解!!!

  • 赞了回答

    参照yii\grid\GridView的这两个方法

    public function renderTableBody()
        {
            $models = array_values($this->dataProvider->getModels());
            $keys = $this->dataProvider->getKeys();
            $rows = [];
            foreach ($models as $index => $model) {
                $key = $keys[$index];
                if ($this->beforeRow !== null) {
                    $row = call_user_func($this->beforeRow, $model, $key, $index, $this);
                    if (!empty($row)) {
                        $rows[] = $row;
                    }
                }
    
                $rows[] = $this->renderTableRow($model, $key, $index);
    
                if ($this->afterRow !== null) {
                    $row = call_user_func($this->afterRow, $model, $key, $index, $this);
                    if (!empty($row)) {
                        $rows[] = $row;
                    }
                }
            }
    
            if (empty($rows)) {
                $colspan = count($this->columns);
    
                return "<tbody>\n<tr><td colspan=\"$colspan\">" . $this->renderEmpty() . "</td></tr>\n</tbody>";
            } else {
                return "<tbody>\n" . implode("\n", $rows) . "\n</tbody>";
            }
        }
    
    public function renderTableRow($model, $key, $index)
        {
            $cells = [];
            /* @var $column Column */
            foreach ($this->columns as $column) {
                $cells[] = $column->renderDataCell($model, $key, $index);
            }
            if ($this->rowOptions instanceof Closure) {
                $options = call_user_func($this->rowOptions, $model, $key, $index, $this);
            } else {
                $options = $this->rowOptions;
            }
            $options['data-key'] = is_array($key) ? json_encode($key) : (string) $key;
    
            return Html::tag('tr', implode('', $cells), $options);
        }
    
  • 2017-05-09 已签到
    连续签到1天,获得了5个金钱
职场新人 等级规则
55/100
资料完整度
10/100
用户活跃度
0/100

Ta的关注

3

Ta的粉丝

0

Ta的访客

1