- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 CActiveDataProvider 和 CListView 输出名称列表。仅当名称与其前面的名称相同时,我才想使用 html 将名称加粗。这些在数据库中不是相同的行,只有“名称”属性相同。
例如,我想要以下内容:
鲍勃
瑞克
史蒂夫
瑞克
瑞克
乔治
由于我使用的是 CListView,因此我使用 $data 中的信息创建部分 View ,其中包含当前列表项。如何访问前一个列表项的属性?
感谢世界各地的 Yii 老兵!
最佳答案
CListView
的每个 itemView
都是 passed a few variables automatically ,即:
$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.
(强调我的)
每个 CListView
小部件都有 property $dataProvider
,并且数据提供者具有属性 $data
which is :
<小时/>an array of the data items currently available (meaning in the current page, with the current sort etc.)
因此,在部分 itemView
中,我们可以访问 dataProvider
的整个数据集,如下所示:
$widget->dataProvider->data;
对于您的示例,类似这样的操作应该有效:
<?php
if ($index > 0 && $widget->dataProvider->data[$index-1]->name == $data->name):
?>
<b><?php echo $data->name; ?></b>
<?php else:
echo $data->test_message;
?>
<?php endif; ?>
关于php - Yii 从 CListView 部分中访问先前的数据项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19760902/
我正在尝试弄清楚如何将一些数据从手机同步到 Android Wear 设备,并且我已经阅读了 developer.android.com 上关于数据项的文章,但是我仍然不清楚究竟如何使用它们。具体来说
$("selector").data("name", null); console.log($("selector").data("name")); 这将打印未定义。 有没有办法在元素的 jQuery
我使用 LINQ 从 CheckBoxList 控件中检索选中的项目: 这里是 LINQ: IEnumerable allChecked = (from ListItem item in Ch
在尝试为 C 堆栈构建测试平台时,我遇到了如何正确显示它的问题。我已经检查了六本书,它们都有一种将堆栈插入堆栈或从堆栈弹出的方法,但没有一本示例说明您如何实际使用这些例程。谁能告诉我模式,这样我就可以
我尝试在 AppEngine 中使用 urlfetch 将 POST 数据发送到服务器。其中一些 POST 数据项具有相同的名称,但具有不同的值。 form_fields = { "data":
我有以下情况(使用 KendoUI): 我有一个绑定(bind)到数据源的网格。当我在网格中选择一行时,我会调用其“change”事件来让所选的 dataItem e 通过其他 HTML 元素显示其值
我基本上是在构建一个快速而肮脏的类(class)目录,其中包含多个层次类别以及属于不同级别的这些类别的类(class)。 在旧的实现中,每个主要类别都有自己的 HTML 页面,与该类别相关的所有类(c
我是 MVC 和 ASP.NET 的新手,希望学习一些东西,所以我正在尝试制作一些简单的应用程序来学习来龙去脉。 好吧,我正在尝试让一个下拉框显示一个图书列表,它会在其中显示图书的标题,但会发布 bo
此行为导致我的项目出现问题。这是正在发生的事情的简化版本。我想了解为什么会发生这种情况,以及如何避免这种情况。我已将 vue 加载到我的网站头部: 这是 Vue 对象: vueObject = ne
我是一名优秀的程序员,十分优秀!