code refactor
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { arrayContainsFieldvalue } from '@/lib/common.js';
|
||||
import { scrollToSelectedItem } from '@/lib/ui.desktop.js';
|
||||
|
||||
import {
|
||||
@@ -96,17 +97,7 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
hasSelectedIcon(row) {
|
||||
if (!this.modelValue || !row || !row.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < row.length; i++) {
|
||||
if (row[i].id === this.modelValue) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return arrayContainsFieldvalue(row, 'id', this.modelValue);
|
||||
},
|
||||
onMenuStateChanged(state) {
|
||||
const self = this;
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { arrayContainsFieldvalue } from '@/lib/common.js';
|
||||
import { scrollToSelectedItem } from '@/lib/ui.desktop.js';
|
||||
|
||||
import {
|
||||
@@ -104,17 +105,7 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
hasSelectedIcon(row) {
|
||||
if (!this.modelValue || !row || !row.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < row.length; i++) {
|
||||
if (row[i].id === this.modelValue) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return arrayContainsFieldvalue(row, 'id', this.modelValue);
|
||||
},
|
||||
onMenuStateChanged(state) {
|
||||
const self = this;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { arrayContainsFieldvalue } from '@/lib/common.js';
|
||||
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
|
||||
|
||||
export default {
|
||||
@@ -81,17 +82,7 @@ export default {
|
||||
this.$emit('update:show', false);
|
||||
},
|
||||
hasSelectedIcon(row) {
|
||||
if (!this.currentValue || !row || !row.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < row.length; i++) {
|
||||
if (row[i].id === this.currentValue) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return arrayContainsFieldvalue(row, 'id', this.currentValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { arrayContainsFieldvalue } from '@/lib/common.js';
|
||||
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
|
||||
|
||||
export default {
|
||||
@@ -101,17 +102,7 @@ export default {
|
||||
this.$emit('update:show', false);
|
||||
},
|
||||
hasSelectedIcon(row) {
|
||||
if (!this.currentValue || !row || !row.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < row.length; i++) {
|
||||
if (row[i].id === this.currentValue) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return arrayContainsFieldvalue(row, 'id', this.currentValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,6 +331,20 @@ export function copyArrayTo(fromArray, toArray) {
|
||||
return toArray;
|
||||
}
|
||||
|
||||
export function arrayContainsFieldvalue(array, fieldName, value) {
|
||||
if (!value || !array || !array.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
if (array[i][fieldName] === value) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function categoriedArrayToPlainArray(object) {
|
||||
const ret = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user