json-editor使用select2并自定义参数

显示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
let code_extra = new JSONEditor(document.getElementById('code_extra'),{
theme: 'bootstrap5',
iconlib: "fontawesome5",
disable_properties: true,
enable_array_copy: true,
disable_edit_json: false,
schema: {
type: "object",
required: ["domaind"],
properties: {
domaind: {
title: "自身域名",
type: "array",
items: {
format: "select2",
title: "域名",
type: "string",
enum: [],
options: {
select2: {
language: 'zh-CN',
width: '100%',
dropdownParent: $('#modal_code_edit'),
allowClear: false,
minimumInputLength: 0,
tags: true,
multiple: false,
ajax: {
url: "{{url_for('select2.api_select2_domaind_det')}}",
dataType: 'json',
delay: 250,
processResults: function(data) {
return {
results: $.map(data.results, function(item) {
return {
text: item.text,
id: item.id
}
})
};
}
}
}
}
},
},
}
}
});

写回

1
2
3
4
5
6
7
8
9
10
11
12
13
14
let row_code_extra = JSON.parse(row.code_extra);
set_json_editor_value(code_extra, row_code_extra);
let res_array = row_code_extra.res;
if (res_array) {
// 查找所有select2控件并处理
$('#code_extra').find('select.form-select').each(function(i, item_select2) {
// 查询已选择的数据
let url='{{url_for("select2.api_select2_domaind_det")}}';
url+='?domaind_ids=' + res_array[i];
// 将结果加载到当前select2选项中
let jq_obj = $(item_select2);
load_select2(url, jq_obj);
})
}

json-editor使用select2并自定义参数
https://itxiaopang.github.io/p/88d983a60da642188279786a4044b5da/
作者
挨踢小胖
发布于
2023年4月18日
许可协议