如何在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'都正确,但是它不起作用.因此,如何在页面加载后在dropdownlist和checkboxlist上选择选定的值? 谢谢
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屋!