【发布时间】:2016-12-19 22:49:58
【问题描述】:
观察以下 $fields 数组,它在刀片中用作输入表单:
$fields = [
'user_id' => [
'label' => 'Opportunity Owner' . $req,
'type' => 'select',
'class' => 'select2',
'opts' => User::whereTenantId(tenant()->id)->whereRole('Admin')->get()->lists('name', 'id')->all()
],
'name' => [
'label' => 'Opportunity Name' . $req,
],
'agent_id' => [
'label' => 'Agent',
'type' => 'select',
'class' => 'select2',
'textAsValue' => false,
'opts' => array_replace([0 => '-- Select Sales Rep --'],
User::whereTenantId(tenant()->id)->whereRole('Admin')->get()->lists('name', 'id')->all()),
],
'description' => [
'label' => 'Description',
'type' => 'textarea'
],
[
'type' => 'submit',
'label' => 'Save',
'class' => 'btn btn-primary !important'
]
];
在“agent_id”部分,如果用户预先分配了一个值,我想预先选择一个值。我知道如何从用户那里获取信息,但我不知道如何在“agent_id”字段中的数组中“选择”一个选项。我需要在选择中显示所有选项,但我希望能够根据与用户关联的 agent_id 编号“选择”一个。我尝试了以下方法:
'agent_id' => [
'label' => 'Agent',
'type' => 'select',
'class' => 'select2',
'textAsValue' => false,
'opts' => array_replace([0 => '-- Select Sales Rep --'],
User::whereTenantId(tenant()->id)->whereRole('Admin')->get()->lists('name', 'id')->all()),
'selected' => {{appropriate number here}}
],
但这没有用。我该怎么做呢?
【问题讨论】:
标签: php forms select laravel-5