Skip to content

Commit 15344d7

Browse files
committed
Group options in function value.
1 parent 07bbb07 commit 15344d7

File tree

1 file changed

+56
-58
lines changed

1 file changed

+56
-58
lines changed

src/fields/core/fieldSelect.vue

+56-58
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
option(v-if="!selectOptions.hideNoneSelectedText", :disabled="schema.required", :value="null", :selected="value == undefined") {{ selectOptions.noneSelectedText || "<Nothing selected>" }}
44

55
template(v-for="item in items")
6-
optgroup(v-if="schema.group && item.group", :label="getGroupName(item)")
7-
option(v-if="schema.group && item.ops", v-for="i in item.ops", :value="getItemValue(i)") {{ getItemName(i) }}
6+
optgroup(v-if="item.group", :label="getGroupName(item)")
7+
option(v-if="item.ops", v-for="i in item.ops", :value="getItemValue(i)") {{ getItemName(i) }}
88

99
option(v-if="!item.group", :value="getItemValue(item)") {{ getItemName(item) }}
1010
</template>
@@ -24,68 +24,66 @@
2424
items() {
2525
let values = this.schema.values;
2626
if (typeof(values) == "function") {
27-
return values.apply(this, [this.model, this.schema]);
27+
return this.dataSorting(values.apply(this, [this.model, this.schema]));
2828
} else
29-
30-
if(this.schema.group){
31-
let array = [];
32-
let arrayElement = {};
33-
34-
values.forEach((item) => {
35-
36-
arrayElement = null;
37-
38-
if(item.group){
39-
// There is in a group.
40-
41-
// Find element with this group.
42-
arrayElement = find(array, i => {return i.group == item.group});
43-
44-
if(arrayElement){
45-
// There is such a group.
46-
47-
arrayElement.ops.push({
48-
id: item.id,
49-
name: item.name
50-
});
51-
}else{
52-
// There is not such a group.
53-
54-
// Initialising.
55-
arrayElement = {
56-
group:"",
57-
ops:[]
58-
};
59-
60-
// Set group.
61-
arrayElement.group = item.group;
62-
63-
// Set Group element.
64-
arrayElement.ops.push({
65-
id: item.id,
66-
name: item.name
67-
});
68-
69-
// Add array.
70-
array.push(arrayElement);
71-
}
72-
}else{
73-
// There is not in a group.
74-
array.push(item);
75-
}
76-
});
77-
78-
// With Groups.
79-
return array;
80-
}
81-
82-
// Without Group.
83-
return values;
29+
return this.dataSorting(values);
8430
}
8531
},
8632
8733
methods: {
8834
35+
dataSorting(values){
36+
let array = [];
37+
let arrayElement = {};
38+
39+
values.forEach((item) => {
40+
41+
arrayElement = null;
42+
43+
if(item.group){
44+
// There is in a group.
45+
46+
// Find element with this group.
47+
arrayElement = find(array, i => {return i.group == item.group});
48+
49+
if(arrayElement){
50+
// There is such a group.
51+
52+
arrayElement.ops.push({
53+
id: item.id,
54+
name: item.name
55+
});
56+
}else{
57+
// There is not such a group.
58+
59+
// Initialising.
60+
arrayElement = {
61+
group:"",
62+
ops:[]
63+
};
64+
65+
// Set group.
66+
arrayElement.group = item.group;
67+
68+
// Set Group element.
69+
arrayElement.ops.push({
70+
id: item.id,
71+
name: item.name
72+
});
73+
74+
// Add array.
75+
array.push(arrayElement);
76+
}
77+
}else{
78+
// There is not in a group.
79+
array.push(item);
80+
}
81+
});
82+
83+
// With Groups.
84+
return array;
85+
},
86+
8987
getGroupName(item){
9088
if(item && item.group){
9189
return item.group;

0 commit comments

Comments
 (0)