如何在 Yii2 html::dropddownlist 上保持选定的值? [英] how to keep selected value on Yii2 html::dropddownlist?
问题描述
我认为有以下代码:
<?=Html::dropdownList('region',null,
ArrayHelper::map(Ethioregion::find()->all(),'region','region'),[
'prompt' => 'Select Region..','style'=>'width:200px',]) ?>
并提交按钮
<?= Html::submitButton('Search', ['name' => 'dele','class' => 'btn btn-primary']) ?>
我的代码运行良好,但我遇到了一个大问题.我选择一个区域并单击搜索按钮,结果正确,当我单击下一页时每页显示 10 个结果,它给了我错误的数据,我注意到这是由于下拉列表中的选定值被重置.我尝试使"Selected'=> true和'Selected'=>'selected',但它不起作用.那么如何在页面加载后选择下拉列表和复选框列表中的选定值?谢谢
my code working well but I have one big problem. I select a region and click the search button, the result comes correctly, and 10 result is shown per page when I click the next page, it gives me false data, I notice this is due to the selected value on the dropdownlist is reset. I tried both making " Selected'=> true, and 'Selected'=>'selected', but it does not work. so how can I make the selected value on dropdownlist and checkboxlist will be selected after the page is loading? thanks
推荐答案
很简单,你只需要传递整数$region_id
:
It is very simple, you must pass integer $region_id
only:
<?=Html::dropdownList('region', $region_id,
ArrayHelper::map(Ethioregion::find()->all(),'region','region'),[
'prompt' => 'Select Region..','style'=>'width:200px',]) ?>
这篇关于如何在 Yii2 html::dropddownlist 上保持选定的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!