dscs63759 2014-12-12 13:10
浏览 109
已采纳

x-editable for yii:连接下拉列表中的字段

I have a CGridView with an EditableColumn with a dropdown select defined like this:

array(
    'name'  => 'Id_department',
    'header'=> 'Department',
    'value' => '$data->Id_department ? Department::model()->findByPk($data->Id_department)->getConcatened() : "[click to edit]"',
    'class' => 'editable.EditableColumn',
    'editable' => array(
        'type'      => 'select',
        'model'     => new Employee(),
        'url'       => $this->createUrl('employee/update'),
        'source'    => $this->createUrl('department/getDepartments'),
        'params'    => array('YII_CSRF_TOKEN' => Yii::app()->request->csrfToken),
    ),
);

with this action in the controller:

public function actionGetDepartments(){
    $models = Department::model->findAll();
    echo CJSON::encode(Editable::source($models, 'Id_department', 'Name'));
    Yii::app()->end();
}

This code builds the dropdown select with the Name attribute as the literal the user see on each option.

The think is that I have to show various attributes, not only one, so I tried to put a function call to a function that concatenates that fields in a single String in the source() function, but it doesn't works:

Editable::source($models, 'Id_department', concatenate())

Is there any way to do this?

  • 写回答

1条回答 默认 最新

  • doulai8128 2014-12-18 14:45
    关注

    I finally found a solution (not the best one, obviously, but useful by the moment).

    Basically, what I'm doing is adding a new attribute called $concatenate_field on the model and putting in it all I need. Then, I can use that field on the function call.

    public function actionGetDepartments(){
        $models = Department::model->findAll();
        foreach($models as $model){
            $model->concatenated_field = $model->getConcatened();
        }
        echo CJSON::encode(Editable::source($models, 'Id_department', 'concatenated_field'));
        Yii::app()->end();
    }
    

    I'm still looking for a better way to do it, but by the moment it works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 网络科学导论,网络控制
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)