0.0.7 • Published 3 years ago

arr-to-enum v0.0.7

Weekly downloads
16
License
MIT
Repository
github
Last release
3 years ago

Usage

$ npm install arr-to-enum
import arrToEnum from 'arr-to-enum'
import arrToEnum from 'arr-to-enum'
const status = [
    {
        name: 'n1',
        value: 1
    },
    {
        name: 'n2',
        value: 2
    }
]

const enumObj = arrToEnum(status)

console.info(enumObj['n1'] === 1) // true
console.info(enumObj['1'] === 'n1') // true

比如在用element-ui Table组件时,进行formatter

<el-table-column label="用户类型" align="center" prop="userTypes" width="200" :formatter="formatUserType"/>

formatUserType(row) {
  // 第二个参数为cacheKey,可以在Table列表循环中快速取出换成的enum对象
  // 第三个参数可以自定义数组中的key
  // 第四个参数可以自定义数组中的value
  return arrToEnum(this.userTypes, 'userTypes', 'name', 'type')[row.subType]
}

License

MIT

Copyright (c) 2020-present, bobby169

0.0.3

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago