0

我无法在加载时以空模式制作多选小部件的左侧列表。当我将null值设置为左侧列表时,它会显示错误。这是我的代码:

  $this->widget('ext.widgets.multiselects.XMultiSelects', array(
                                    'leftTitle' => '',
                                    'leftName' => 'Certificate[selected][]',
                                    'leftList' => SpecificCertification::model()->findCertificate(),// here I need to make the list empty
                                    'rightTitle' => '',
                                    'rightName' => 'Certificate[all][]',
                                    'rightList' => SpecificCertification::model()->findCertificates(),
                                    'size' => 10,
                                ));

如何使左侧列表为空?

4

1 回答 1

0

您需要打开文件小部件 XMultiSelects.php 并对其进行修改以满足您的需要

public function init()
    {
/* Comment out the below validation
        if(!isset($this->leftList))
        {
            throw new CHttpException(500,'"leftList" have to be set!');
        }
        if(!isset($this->rightList))
        {
            throw new CHttpException(500,'"rightList" have to be set!');
        }
*/
    }

为 leftList 和 rightList 添加验证,如下所示

if($this->leftList){
            foreach($this->leftList as $value=>$label)
            {
                echo "<option value=\"{$value}\">{$label}</option>\n";
            }
        }

if($this->rightList){
        foreach($this->rightList as $value=>$label)
            {
                echo "<option value=\"{$value}\">{$label}</option>\n";
            }
        }

之后,您可以像您所做的那样为它们设置 null

于 2013-08-06T12:00:25.447 回答