现在的位置: 首页 > 综合 > 正文

CListView 隔行变色

2013年12月08日 ⁄ 综合 ⁄ 共 793字 ⁄ 字号 评论关闭

Yii 中的CGridview 很好用,但是有时候不能满足我们的高制定性,这个时候更加灵活的CListView 就可以帮助我们解决这些问题。

CListView 本身处理方式为,在一个总的页面中写入你需要的数据,之后在一个模板页中来制定你每一条数据怎么处理!

如果我要每隔行修改一下样式要怎么处理呢

itemView 属性
public string $itemView;

the view used for rendering each data item. This property value will be passed as the first parameter to either
CController::renderPartial or
CWidget::render
to render each data item. In the corresponding view template, the following variables can be used in addition to those declared in
viewData:

  • $this: refers to the owner of this list view widget. For example, if the widget is in the view of a controller, then
    $this refers to the controller.
  • $data: refers to the data item currently being rendered.
  • $index: refers to the zero-based index of the data item currently being rendered.
  • $widget: refers to this list view widget instance.

上面有个$index属性.我们可以改变这个属性得到

如:

<?php

     if ($index%2==0){

                   echo "<br>"

}

?>

抱歉!评论已关闭.