Javascript 选择“设置”,仅在第一次使用时有效。item函数第二次不起作用

Javascript 选择“设置”,仅在第一次使用时有效。item函数第二次不起作用,javascript,jquery,select,option,selectize.js,Javascript,Jquery,Select,Option,Selectize.js,这是我的select脚本的代码: var $select = $('#select-links').selectize({ theme: 'links', maxItems: 1, valueField: 'id', searchField: 'title', options: [ {id: 1,

这是我的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);
var$select=$('#选择链接')。选择({
主题:"连结",,
最大项目:1,
valueField:'id',
searchField:'标题',
选项:[
{id:1,标题:“corp.blpnexi.com”,前言:“Primary/Std”,值:'https://corp.blpnexi.com,安全:'https://'},
{id:2,标题:'alpha.vidyo.com',前言:'Secondary/DR',值:'https://alpha.vidyo.com,安全:'https://'},
],
呈现:{
选项:函数(数据、转义){
返回“”+
''+escape(数据.前言)+''+
''+转义(数据安全)+''+
''+转义(数据.标题)+''+
'';
},
项目:功能(数据、转义){
document.getElementById(“提交门户选择”).value=data.value;
var门户=data.value;
$(“#门户”).val(门户).change();
localStorage.portal=portal;
console.log(“所选数据:“+data.title”);
var classOf='titleI2';
如果(data.title==“corp.blpnexi.com”){
classOf='titleI';
}
返回“”+
''+escape(数据.前言)+''+
''
+''+转义(数据安全)+''+
''+转义(数据.标题)+''+
''+
'';
}
},
创建:函数(输入){
返回{
id:0,
标题:输入,
前言:"#",,
值:null,
安全:“https://”
};
}
});
var selectize=$select[0]。selectize;
选择设置值(1);
我设置了一些断点,并尝试调试。 当我选择一个值时,它进入item函数。其中,我将LocalStorage.portal设置为该项的dava.value。
这在第一次使用时有效,但在第二次尝试使用它时,它不会输入此代码,也不会更改,将本地存储保留为我首先设置的值。如何使其运行该代码?或者,如果现在,如何在需要时获取正确的值?

我为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;
                }