简体   繁体   中英

cannot read property addOption on undefine in javascript selectize

I am trying to implement search and each time getting this error... cannot read property 'addOption' on undefine in javascript selectize. I have checked that my result array have data.

My js code.

 var selectSearchValue, $selectSearchValue;
        var results = [];
        var list_selector = $('.data-list');

        list_selector.each(function (value) {

            results.push({
                id: $(this).attr('data-id'),
                name: $(this).attr('data-name'),
                code: $(this).attr('data-code'),
                hall: $(this).attr('data-hall'),
                location: $(this).attr('data-location')


            });

        });

        selectSearchValue.addOption(results);
        selectSearchValue.refreshOptions();


        $selectSearchValue = $('#searchItems').selectize({
            valueField: 'id',
            labelField: 'name',
            searchField: ['hall', 'name', 'code', 'location'],
            render: {
                option: function (item, escape) {
                    return '<div class="item-wrap">' +
                            '<span class="name">' + escape(item.hall) + '</span>' +
                            '<span class="code">' + escape(item.code) + '</span>' + '<div class="clearfix"></div>' +
                            '<span class="venue-name">' + escape(item.name) + ', </span>' +
                            '<span class="location">' + escape(item.location) + '</span>' +
                            '</div>';


                }


            }
        });
        selectSearchValue = $selectSearchValue[0].selectize;

您试图在定义selectSearchValue (第42行)之前向selectSearchValue (第19行)添加选项。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM