选择,只适用于第一次。项目功能第二次不起作用

Selectize, only works the first time. the item function does not work the second time

这是我的 select 脚本的代码:

 var $select = $('#select-links').selectize({
                theme: 'links',
                maxItems: 1,
                valueField: 'id',
                searchField: 'title',
                options: [
                    {id: 1, title: 'corp.blpnexi.com', preface: 'Primary/Std', value: 'https://corp.blpnexi.com' , secure: 'https://'},
                    {id: 2, title: 'alpha.vidyo.com', preface: 'Secondary/DR', value: 'https://alpha.vidyo.com' , secure: 'https://'},
                ],
                render: {
                    option: function(data, escape) {
                        return '<div class="option">' +
                                '<span class="preface">' + escape(data.preface) + '</span>' +
                                '<span class="secureClass">' + escape(data.secure) + '</span>' +
                                '<span class="title">' + escape(data.title) + '</span>' +
                            '</div>';
                    },
                    item: function(data, escape) {
                        document.getElementById("submit-portal-select").value = data.value;
                        var portal = data.value;
                        $("#portal").val(portal).change();
                        localStorage.portal = portal;
                        console.log("data selected:" + data.title);
                        var classOf = 'titleI2';
                        if(data.title === "corp.blpnexi.com"){
                            classOf = 'titleI';
                        }
                        return '<div class="option">' +
                                '<span class="prefaceI">' + escape(data.preface) + '</span>' +
                                '<span class="divClass">'
                                +'<span class="secureClass">' + escape(data.secure) + '</span>' +
                                '<span class='+ classOf+'>' + escape(data.title) + '</span>' +
                                '</span>'+
                            '</div>';
                    }
                },
                create: function(input) {
                    return {
                        id: 0,
                        title: input,
                        preface: '#',
                        value: null,
                        secure: 'https://'
                    };
                }
            });
            var selectize = $select[0].selectize;
            selectize.setValue(1);

我已经设置了一些断点,并尝试调试。 当我select一个值时,就进入了item函数。我将 thelocalStorage.portal 设置为该项目的 dava.value。 这第一次有效,但我第二次尝试使用它时,它没有输入此代码,也没有更改,将我的 localStorage 保留为我首先设置的值。我怎样才能使它成为 运行 那个代码?或者如果现在,我怎样才能在需要时获取正确的值?

我为 onChange 添加了回调并成功了:

  onChange: function(value) {
                    console.log("data selected:" + value);
                    var portal;
                    if(value == 1){
                        portal = "https://corp.blpnexi.com";
                    }else{
                        portal = "https://alpha.vidyo.com";
                    }
                    document.getElementById("submit-portal-select").value = portal;
                    localStorage.portal = portal;
                }