瀏覽代碼

Feafactor: Move AutoComplete filter function as utils

pull/168/head
winkidney 5 年之前
父節點
當前提交
b7f24b83be
共有 2 個文件被更改,包括 17 次插入13 次删除
  1. +2
    -13
      pinry-spa/src/components/pin_edit/FilterSelect.vue
  2. +15
    -0
      pinry-spa/src/components/utils/AutoComplete.js

+ 2
- 13
pinry-spa/src/components/pin_edit/FilterSelect.vue 查看文件

@@ -38,21 +38,10 @@
<script>
import API from '../api';
import ModelForm from '../utils/ModelForm';
import AutoComplete from '../utils/AutoComplete';

const fields = ['name'];

function getFilteredOptions(options, filterText) {
return options.filter(
(option) => {
const index = option.name
.toString()
.toLowerCase()
.indexOf(filterText.toLowerCase());
return index >= 0;
},
);
}

function getBoardFromResp(boardObject) {
return { name: boardObject.name, value: boardObject.id };
}
@@ -62,7 +51,7 @@ function getAvailableOptions(vm, filter) {
if (filter === '' || filter === null) {
availableOptions = vm.allOptions;
} else {
availableOptions = getFilteredOptions(
availableOptions = AutoComplete.getFilteredOptions(
vm.allOptions, vm.form.name.value,
);
}


+ 15
- 0
pinry-spa/src/components/utils/AutoComplete.js 查看文件

@@ -0,0 +1,15 @@
function getFilteredOptions(options, filterText) {
return options.filter(
(option) => {
const index = option.name
.toString()
.toLowerCase()
.indexOf(filterText.toLowerCase());
return index >= 0;
},
);
}

export default {
getFilteredOptions,
};

Loading…
取消
儲存