mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-09 23:16:18 +08:00
updateSelect 支持指定 id
This commit is contained in:
parent
49c6e6b536
commit
b248980bc6
@ -235,26 +235,25 @@ quickcommand = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 更新选项列表
|
// 更新选项列表
|
||||||
updateSelectList: function (selects) {
|
updateSelectList: function (opt, id) {
|
||||||
if(!$('#selectBox').length) throw '当前没有选择列表, 请结合 quickcommand.showSelectList 使用'
|
if(!$('#selectBox').length) throw '当前没有选择列表, 请结合 quickcommand.showSelectList 使用'
|
||||||
let data = $('#selectBox').data('options')
|
let data = $('#selectBox').data('options')
|
||||||
let num = data.length
|
let num = data.length
|
||||||
|
typeof id == 'undefined' && (id = num)
|
||||||
|
if (id > num) throw 'id 不能大于当前列表数'
|
||||||
let optionType = $('#selectBox').data('type')
|
let optionType = $('#selectBox').data('type')
|
||||||
selects instanceof Array || (selects = [selects])
|
let item = { id: id }
|
||||||
let item
|
if (optionType == 'json') {
|
||||||
selects.forEach(s => {
|
item.text = ''
|
||||||
item = {id: num++}
|
if (!(opt instanceof Object)) throw '更新的选项格式与当前的不一致'
|
||||||
if (optionType == 'json') {
|
Object.keys(opt).forEach(k => item[k] = opt[k])
|
||||||
item.text = ''
|
opt.icon && (item.text += `<div class="icon"><img src="${opt.icon}"></div>`)
|
||||||
Object.keys(s).forEach(k => item[k] = s[k])
|
opt.title && (item.text += `<div class="title">${opt.title}</div>`)
|
||||||
s.icon && (item.text += `<div class="icon"><img src="${s.icon}"></div>`)
|
opt.description && (item.text += `<div class="description">${opt.description}</div>`)
|
||||||
s.title && (item.text += `<div class="title">${s.title}</div>`)
|
} else {
|
||||||
s.description && (item.text += `<div class="description">${s.description}</div>`)
|
item.text = opt
|
||||||
} else {
|
}
|
||||||
item.text = s
|
data[id] && (data[id] = item) || data.push(item)
|
||||||
}
|
|
||||||
data.push(item)
|
|
||||||
})
|
|
||||||
$('#selectBox').data('options', data).val(null).trigger('change')
|
$('#selectBox').data('options', data).val(null).trigger('change')
|
||||||
$("#quickselect .select2-search__field").trigger('input')
|
$("#quickselect .select2-search__field").trigger('input')
|
||||||
modWindowHeight($('.select2-results').outerHeight())
|
modWindowHeight($('.select2-results').outerHeight())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user