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 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决