vue Treeselect后台返回数据转换为指定格式
lynnk
2601 人已围观
<el-form-item :label="$t('sysManage.department.table.parDepart')"> <treeselect :options="preDepartTreeData" :normalizer="normalizer" v-model="oneDepart.parentId" :placeholder="$t('sysManage.department.parDepartInput')" ></treeselect> </el-form-item> <script> // import the component import Treeselect from "@riophae/vue-treeselect"; // import the styles import "@riophae/vue-treeselect/dist/vue-treeselect.css"; import { truncate } from 'fs'; export default { components: { Treeselect }, data() { return { oneDepart: Object.assign({}, defaultDepart), preDepartTreeData: [] ], // 后台返回的数据和VueTreeselect要求的数据结构不同,需要进行转换 normalizer(node) { //去掉children=[]的children属性 if (node.children && !node.children.length) { delete node.children; } return { id: node.id, label: node.name, children: node.children } } } } }; </script>
发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。