Skip to content

Commit

Permalink
Group options in function value.
Browse files Browse the repository at this point in the history
  • Loading branch information
hansi90 committed Oct 16, 2017
1 parent 07bbb07 commit 15344d7
Showing 1 changed file with 56 additions and 58 deletions.
114 changes: 56 additions & 58 deletions src/fields/core/fieldSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
option(v-if="!selectOptions.hideNoneSelectedText", :disabled="schema.required", :value="null", :selected="value == undefined") {{ selectOptions.noneSelectedText || "<Nothing selected>" }}

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

option(v-if="!item.group", :value="getItemValue(item)") {{ getItemName(item) }}
</template>
Expand All @@ -24,68 +24,66 @@
items() {
let values = this.schema.values;
if (typeof(values) == "function") {
return values.apply(this, [this.model, this.schema]);
return this.dataSorting(values.apply(this, [this.model, this.schema]));
} else
if(this.schema.group){
let array = [];
let arrayElement = {};
values.forEach((item) => {
arrayElement = null;
if(item.group){
// There is in a group.
// Find element with this group.
arrayElement = find(array, i => {return i.group == item.group});
if(arrayElement){
// There is such a group.
arrayElement.ops.push({
id: item.id,
name: item.name
});
}else{
// There is not such a group.
// Initialising.
arrayElement = {
group:"",
ops:[]
};
// Set group.
arrayElement.group = item.group;
// Set Group element.
arrayElement.ops.push({
id: item.id,
name: item.name
});
// Add array.
array.push(arrayElement);
}
}else{
// There is not in a group.
array.push(item);
}
});
// With Groups.
return array;
}
// Without Group.
return values;
return this.dataSorting(values);
}
},
methods: {
dataSorting(values){
let array = [];
let arrayElement = {};
values.forEach((item) => {
arrayElement = null;
if(item.group){
// There is in a group.
// Find element with this group.
arrayElement = find(array, i => {return i.group == item.group});
if(arrayElement){
// There is such a group.
arrayElement.ops.push({
id: item.id,
name: item.name
});
}else{
// There is not such a group.
// Initialising.
arrayElement = {
group:"",
ops:[]
};
// Set group.
arrayElement.group = item.group;
// Set Group element.
arrayElement.ops.push({
id: item.id,
name: item.name
});
// Add array.
array.push(arrayElement);
}
}else{
// There is not in a group.
array.push(item);
}
});
// With Groups.
return array;
},
getGroupName(item){
if(item && item.group){
return item.group;
Expand Down

0 comments on commit 15344d7

Please sign in to comment.