naive-ui/packages/utils/component/processOptions.js
2019-08-25 16:58:04 +08:00

18 lines
466 B
JavaScript

import cloneDeep from 'lodash/cloneDeep'
export default function processedOptions (options) {
const decoratedOptions = cloneDeep(options).map((option, index) => {
return {
...option,
id: index
}
})
const length = decoratedOptions.length
decoratedOptions.forEach((option, i) => {
option.prev = decoratedOptions[(i + length - 1) % length]
option.next = decoratedOptions[(i + length + 1) % length]
})
return decoratedOptions
}