I have a form done with semantic-ui and one of the elements is a dropdown that has values pulled from a remote url. It works fine for adding things but how do I set a value for the dropdown when editing.
If a user searched for a country and submitted the form with United Kingdom
how do I display the selected value when the user wants to edit the object?
$('.ui.dropdown.country_select').dropdown('setting', {
apiSettings: {
url: '../countries/{query}'
}
});
答案 0 :(得分:0)
经过一番挖掘后找到答案:
var dd = $('.ui.dropdown.country_select').dropdown('setting', {
apiSettings: {
url: '../countries/{query}'
}
});
dd.dropdown('set text', 'yahoo');
dd.dropdown('set value', 'google');
答案 1 :(得分:0)
我遇到了类似的问题,但是下拉列表是多个,可搜索和远程数据。对我来说,解决方案是只播种与默认值对应的<option>
标签。因此,使用您的代码示例:
$('.ui.dropdown.country_select').dropdown('setting', {
apiSettings: {
url: '../countries/{query}'
}
});
// Assuming defaultValue = '1';
<select class="ui dropdown country_select">
<option value="1" selected>Default Value Item</option>
</select>
然后下拉列表应该在初始化后用远程源覆盖选项。