element树组件el-tree默认选中展开某些节点

element树组件el-tree默认选中展开某些节点

2023年6月22日发(作者:)

element树组件el-tree默认选中展开某些节点1.需求⽐如像这种需求,他这是点击某个节点时发送请求,然后获取他下⾯的⼦节点,把⼦节点追加上去,但是呢,如果只追加不默认展开的话就会有个问题,就是点击了,⼦元素追加了,但是没展开,就导致我需要⼿动点两次展开,⽤户体验不好1.在template中:

写个数组默认装展开节点的id,唯⼀标识,就是上⾯的node-key> {{ }} 2.在data中:data () { defaultShowKeys: [], defaultProps: { children: 'children', label: 'classDesc' }, classDesc: ''}3.在methods中:methods: { //

获取最外层⽗级元素 doQuery () { let _this = this _('xxx/xxx/xxx/?classDesc=' + esc).then(function (res) { if ( === '0') { _ta = _h(item => { dflag = false //

默认添加⼀个属性,⽤于记录它的点击状态 ag = true en = [] }) } }).catch(function () { }); }, handleNodeClick (data) { let _this = this dflag = !dflag let params = { pageNum: 1, pageSize: 100000, pageSize: 100000, parentCode: ode, parentDesc: esc //

⽗类名称 } _('xxx/xxx/xxx', {params: params}).then(function (res) { if ( === '0') { let tree = h(item => { for (let index in en) { if (ode === en[index].classCode) { // _this.$(en[index]) // _this.$(item, data); return false; } } dflag = false _this.$(item, data); let node = _this.$e(item) if (uctor === Array) { ag = true } else if (uctor === Object) { //

如果祖⽗是对象就是第三级了,那么就不允许再新增 ag = false } }) let arr = [] if ( === 0) { dflag = false } else { if (dflag) { //

如果点击的状态是true,那么就存到数组⾥ for (let index in _tShowNodes) { if (ode === _tShowNodes[index]) { //

如果已经存在就跳过 return false } } _(ode) } else { //

如果是false,证明点击的是关闭,那么找到这个,从数组中删除 _h((item1, index) => { if (item1 === ode) { //

判断当前节点是否存在,

存在就添加到要删除的数组⾥ (item1) } if ( > 0) { //

要判断⼉⼦有没有展开的,如果⼉⼦有展开的就要删除掉,否则,⼉⼦的还是展开状态,⽗亲、爷爷辈的也会被展开, for (let index in en) { if (item1 === en[index].classCode) { (item1) return false; } } } }) } } h(item4 => { for (let index in _tShowNodes) { if (item4 === _tShowNodes[index]) { _(index, 1) return false; } } }) } }).catch(function () { }); }); },}

发布者:admin,转转请注明出处:http://www.yc00.com/news/1687383703a5999.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信