2
我有一個多選擇下拉菜單,當我創建「項目」它工作得很好。yii2多選select dropdown remember selected
如果我想編輯創建的「項目」,它不記得在創建「項目」時我在下拉菜單中選擇了什麼。
它將其保存到數據庫中,它顯示它沒有問題,但是如果要編輯,則需要再次選擇它們。
有沒有辦法根據數據庫自動選擇它們? (我仍然希望能夠編輯它,但我希望它們可以被默認選中)。
echo $form->field($model, 'company_id')->dropDownList($items_company, ['prompt' => 'Select Company','style' => 'width:400px;','onchange'=>'
$.post("index.php?r=project/lists&id='.'"+$(this).val(), function(data) {
$("select#client").html(data);
});
']);
if($model->client){
echo $form->field($model, 'client')
->dropDownList(
$items_client,
['id'=>'client','multiple' => true,'style' => 'width:400px;']
);
}