yii2:drop-down list for multiple values concat in one line

后端 未结 4 1940
梦如初夏
梦如初夏 2020-12-14 17:06

for my drop-down list I am using this code.

field($medicinerequest, \'[\' . $id . \']\' . \'medicine_name\')
->DropDownList(ArrayHelper::         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-14 18:01

    ArrayHelper::map($array, $from, $to, $group) uses ArrayHelper::getValue() to obtain the values of $from, $to and $group. ArrayHelper::getValue() allows you to pass closures.

    The anonymous function signature should be: function($array, $defaultValue).

    As such you can set $to as

    ArrayHelper::map(
        \app\models\Medicine::find()->asArray()->all(),
        'id',
        function($model) {
            return $model['medicine_name'].'-'.$model['medicine_id'];
        }
    )
    

提交回复
热议问题