EasyUI Forum
November 04, 2025, 04:53:46 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Combobox: add item  (Read 28458 times)
Berzy
Newbie
*
Posts: 7


View Profile Email
« on: July 23, 2014, 08:11:22 AM »

how can I add items to a combobox?

my c#

<select class="easyui-combobox" id="FormatoCarta" name="FormatoCarta">
                            @foreach (var item in @Model.FormatiCarta)
                            {
                                String selected = String.Empty;
                                if (@Model.Defaults != null)
                                {
                                    if (item.Id.Equals(@Model.Defaults.IDFormatoCarta))
                                    {
                                        selected = "selected=selected";
                                    }
                                }
                                <option @selected value=@item.Id>@item.Nome</option>
                            }
                        </select>


my add function (not working)
$('#FormatoCarta').append('<option value=\"' + msg + '\">' + $('#NewNomeFormato').val() + '</option>');

it add the option, but the combobox don't reflect the change.

Thankyou!!
Logged
leela
Newbie
*
Posts: 29


View Profile Email
« Reply #1 on: July 23, 2014, 09:22:46 AM »

You need to use 'loadData' of combobox, for the options to be set to it.

Declare combobox as
Code:
<input class="easyui-combobox" id="FormatoCarta" name="FormatoCarta" data-options="valueField:'id',textField:'name'">

Code:
<script>
var loadData = [];
</script>
@foreach (var item in @Model.FormatiCarta)
                            {
                                String selected = String.Empty;
                                if (@Model.Defaults != null)
                                {
                                    if (item.Id.Equals(@Model.Defaults.IDFormatoCarta))
                                    {
                                        selectedId = item.Id;
                                    }
                                }
<script>
loadData.push({"id":item.Id,"name":item.name});
</script>
                            }


<script>
$('#FormatoCarta').combobox({data:loadData});
$('#FormatoCarta').combobox('setValue', selectedId );
</script>
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!