对于我的下拉列表,我正在使用此代码.
<?= $form->field($medicinerequest, '[' . $id . ']' . 'medicine_name')
->DropDownList(ArrayHelper::map(\app\models\Medicine::find()
->asArray()->all(), 'id', 'medicine_name','medicine_id' ),
[ 'prompt' => 'Please Select' ])?>
Run Code Online (Sandbox Code Playgroud)
我正在获取图片中的下拉列表.但是我希望它在一行中用连字符( - )连接起来.我怎样才能做到这一点?

top*_*her 49
ArrayHelper::map($array, $from, $to, $group)使用ArrayHelper::getValue()得到的值$from,$to和$group.ArrayHelper::getValue()允许你传递闭包.
匿名函数签名应该是:
function($array, $defaultValue).
因此你可以设置$to为
ArrayHelper::map(
\app\models\Medicine::find()->asArray()->all(),
'id',
function($model) {
return $model['medicine_name'].'-'.$model['medicine_id'];
}
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15862 次 |
| 最近记录: |