如何扩展 CListView 以删除额外的 yii 添加的标记? [英] How to extend CListView in order to remove extra yii added markup?

查看:25
本文介绍了如何扩展 CListView 以删除额外的 yii 添加的标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重点是从 CListView 渲染中移除那两个 div:

<div class="items">

我一直在寻找:

https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/CBaseListView.php#L123

但我没有发现与那里的那两个 div 相关.

谁能分享一下,我们应该扩展什么才能使这成为现实?

这是所需输出的更新:

<article class="itemthing">列出数据</文章><article class="itemthing">列出数据</文章><article class="itemthing">列出数据</文章>

解决方案

你最好从 CListView 本身扩展,但为 run() CBaseListView 中的方法renderItems() 的新实现 CListView 中的方法,例如:

Yii::import('zii.widgets.CListView');类 MListView 扩展 CListView{公共函数运行(){$this->registerClientScript();//这一行渲染第一个 div//echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";$this->renderContent();$this->renderKeys();//echo CHtml::closeTag($this->tagName);}公共函数 renderItems(){//这一行渲染了第二个div//echo CHtml::openTag($this->itemsTagName,array('class'=>$this->itemsCssClass))."\n";//从函数中复制原始代码//echo CHtml::closeTag($this->itemsTagName);}}

请注意,某些默认的 clistview 功能将无法仅使用这么多,因为 如果没有标识此列表视图的 id,jquery.yiilistview.js 将无法工作.

根据您更新的问题,您可以这样做,然后:

<?php$this->widget('ext.extendedwidgets.MListView',array('id'=>'some-id',//与你在 div 中指定的相同 id//... 剩下的'模板' =>'{items}',//如下面的聊天所示));

The point is to remove from CListView render, those two divs:

<div id="yw0" class="list-view">
<div class="items">

I've been looking here:

https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/CBaseListView.php#L123

But I found nothing related with those two divs there.

Can anyone please share, what should we extend in order for make this a reality ?

Here's an update of the desired output:

<div>
  <article class="itemthing">
    list data
  </article>
  <article class="itemthing">
    list data
  </article>
  <article class="itemthing">
    list data
  </article>
</div>

解决方案

You'd be better off extending from CListView itself, but write new implementations for run() method in CBaseListView and a new implementation for the renderItems() method in CListView, for example:

Yii::import('zii.widgets.CListView');
class MListView extends CListView{
    public function run(){
            $this->registerClientScript();
            // this line renders the first div
            //echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n"; 

            $this->renderContent();
            $this->renderKeys();

            //echo CHtml::closeTag($this->tagName);
    }

    public function renderItems(){
            //this line renders the second div
            //echo CHtml::openTag($this->itemsTagName,array('class'=>$this->itemsCssClass))."\n"; 
            // copy original code from the function
            //echo CHtml::closeTag($this->itemsTagName);
    }
}

Edit:

Be aware that some of the default clistview functionality will not work with only this much, because the jquery.yiilistview.js will not work without an id, that identifies this listview.

Edit:

From your updated question, you can do this, then:

<div id="some-id">
<?php
    $this->widget('ext.extendedwidgets.MListView',array(
        'id'=>'some-id', // same id you specified in the div
        //... rest of it
        'template' => '{items}', // as seen in the chat below
    ));
</div>

这篇关于如何扩展 CListView 以删除额外的 yii 添加的标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆