簡體   English   中英

無法在javascript selectize中的undefine上讀取屬性addOption

[英]cannot read property addOption on undefine in javascript selectize

我正在嘗試實施搜索,每次收到此錯誤...無法在javascript selectize中讀取未定義的屬性'addOption'。 我檢查了我的結果數組是否有數據。

我的js代碼。

 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行)添加選項。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM