【发布时间】:2017-05-21 05:12:45
【问题描述】:
这是我的选择脚本的代码:
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);
我设置了一些断点,并尝试调试。 当我选择一个值时,它会进入项目功能。我将 localStorage.portal 设置为该项目的 dava.value。 这第一次有效,但我第二次尝试使用它时,它没有输入此代码,也没有改变,将我的 localStorage 保留为我首先设置的值。我怎样才能让它运行该代码?或者如果现在,我怎样才能在需要时获取正确的值?
【问题讨论】:
标签: javascript jquery select option selectize.js