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:

    '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'));

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'));

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

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



  • ¥15 画个数据流程图,手画也行
  • ¥60 AS自带模拟器AVD Root 和 Xposed安装
  • ¥15 Esp32的microPython设备中main.py文件无法开机自启动
  • ¥30 哪位搞Android的编程师可以帮我远程一下,悬赏30元
  • ¥15 solidity部署上合约,可以mint,也继承接口了,在区块链也不显示代币名字
  • ¥15 讨论 博士论文交互项怎么讨论?
  • ¥50 在集成BiLSTM和GCN模型时遇到了问题
  • ¥33 集成BiLSTM模型和GCN模型时,前模型的输出不匹配后模型的输入
  • ¥15 关于液体厚度提取,和铺展轨迹数据化处理
  • ¥20 对方微信是wxid如何添加成好友?或者转换成微信号?