From b248980bc67bc1c4370d114f8248f525e60093ee Mon Sep 17 00:00:00 2001 From: fofolee Date: Mon, 13 Jul 2020 20:35:03 +0800 Subject: [PATCH] =?UTF-8?q?updateSelect=20=E6=94=AF=E6=8C=81=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/preload.js | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/preload.js b/src/preload.js index 6416c4d..51dc03c 100644 --- a/src/preload.js +++ b/src/preload.js @@ -235,26 +235,25 @@ quickcommand = { }, // 更新选项列表 - updateSelectList: function (selects) { + updateSelectList: function (opt, id) { if(!$('#selectBox').length) throw '当前没有选择列表, 请结合 quickcommand.showSelectList 使用' let data = $('#selectBox').data('options') let num = data.length + typeof id == 'undefined' && (id = num) + if (id > num) throw 'id 不能大于当前列表数' let optionType = $('#selectBox').data('type') - selects instanceof Array || (selects = [selects]) - let item - selects.forEach(s => { - item = {id: num++} - if (optionType == 'json') { - item.text = '' - Object.keys(s).forEach(k => item[k] = s[k]) - s.icon && (item.text += `
`) - s.title && (item.text += `
${s.title}
`) - s.description && (item.text += `
${s.description}
`) - } else { - item.text = s - } - data.push(item) - }) + let item = { id: id } + if (optionType == 'json') { + item.text = '' + if (!(opt instanceof Object)) throw '更新的选项格式与当前的不一致' + Object.keys(opt).forEach(k => item[k] = opt[k]) + opt.icon && (item.text += `
`) + opt.title && (item.text += `
${opt.title}
`) + opt.description && (item.text += `
${opt.description}
`) + } else { + item.text = opt + } + data[id] && (data[id] = item) || data.push(item) $('#selectBox').data('options', data).val(null).trigger('change') $("#quickselect .select2-search__field").trigger('input') modWindowHeight($('.select2-results').outerHeight())