开发者

Remove all options from dijit.form.FilteringSelect

I need help withe deleting all options from FilteringSelect.

Html code of select:

        <select id="kat" dojoType="dijit.form.FilteringSelect" style="width:170px; height: 22px;" name="form[kategorija]">
            <option value="izbira">Izberi...</option>
            <?php
            $rezKat = $tabelaKategorij->dobiVseKategorije();
          foreach($rezKat as $rowKat):
    echo '<option id="optkat" value="'.$rowKat['id'].'">'.$rowKat['ime_kategorije'].'</option>';                         
endforeach;
        ?>
        </select>

The function for deleting all options

function izbrisiSeznam()
{
     var j;
     for (j = dojo.byId("kat").length - 1; j>=0; j--)
     {
        dojo.byId("kat").remove(j);
     }
}

When i call this function in..

$(document).ready(function () {
    izbrisiSeznam();
});

Then works perfectly. But when i try to call function in onSuccess then doesn't recognize selecet.

Example:

function dodajKategorijo()
    {
            var ime_kategorije = $('#ime_kategorije').val();
            if(ime_kategorije!= '')
            {
                    $.ajax({
                        type: "GET",
                        url: "<?php echo constant('REL_PATH'); ?>/admin/dodajkategorijo/",
                        dataType: 'json',
                        data:
                        {
                          id: ime_kategorije
                        },
                        success: function(data) {

                            var vsebina = '';
                            vsebina = '<div id="kategorija'+data.id+'" class="form-field clear">'+
                                      '<label for="'+data.ime_kategorije+'" class="form-label size-80 fl-space2">&nbsp;</label>'+
                                      '<input disabled value="'+data.ime_kategorije+'" type="text" id="'+data.id+'" class="required size-140 text fl" name="form[naslov]" />'+
                                      '<a href="javascript:void:(0)" onClick="izbrisiKategorijo('+data.id+')"><img src="<?php echo constant('REL_PATH'); ?>/images/button/delete.png" class="gumbek" alt="" /></a>'
                                      '</div>';

                       开发者_Go百科     $('#nalozene_kategorije').append(vsebina);

                            izbrisiSeznam();
                        }
                    });
                    return true;
                }
                else
                {
                    alert('Vnesti morate ime kategorije');
                    return false;
                }
    }


To remove all options from your filtering select:

dijit.byId('kat').removeOption(dijit.byId('kat').getOptions());

Worked for me in Dojo 1.7.2


The following works for me (dojo 1.8.3):

var node = document.getElementById("MY_SELECT_ID");
while (node.firstChild) node.removeChild(node.firstChild);

This is the non-jQuery version of the answer by user2243420


Here is how to remove all options programmatically. Assign a new blank store. Then set the value to blank.

        // Define it programatically:
        _cellsSelect = new dijit.form.FilteringSelect({
            id : "cells" + _instance,
            store : cellStore,
            searchAttr : "name"
        });

        // Clear it:
        _cellsSelect.store = new dojo.store.Memory({
                data : [ {
                    name : '',
                    id : ''
                } ]
            });
        _cellsSelect.set('value', '');


we can set an empty array to the Filtering select widgets store.

dijit.byId('widgetId').store.data.splice(0,dijit.byId('widgetId').store.data.length);

or simply,

dijit.byId('widgetId').store.data = [];

Or you can set the store itself as null. (But, to add new options after this, you need to recreate the store again, before adding up the new options).

dijit.byId('widgetId').store = null;


few things,

1) dojo.byId("kat") should be dijit.byId("kat")

2) i think there is no remove method on filtering select.

3) to remove all options you may use this

dijit.byId('kat').dropDown.destroy()

thanks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜