Code Monkey home page Code Monkey logo

Comments (4)

JauSingSing avatar JauSingSing commented on May 28, 2024

为什么不直接设置 value 的值呢?

from element-plus.

JaxonJay avatar JaxonJay commented on May 28, 2024

为什么不直接设置 value 的值呢?
因为返回的数据是所有选中的和半选中的id,用value和v-model都无法正确回显值,所以想着用setCheckedKeys方法的第二个参数设置只设置选中的叶子节点状态
另外其实是可以用别的方法解决的,但是发现了这个问题,不知道是bug还是设计如此,所以提了个issue

from element-plus.

JauSingSing avatar JauSingSing commented on May 28, 2024

为什么不直接设置 value 的值呢?
因为返回的数据是所有选中的和半选中的id,用value和v-model都无法正确回显值,所以想着用setCheckedKeys方法的第二个参数设置只设置选中的叶子节点状态
另外其实是可以用别的方法解决的,但是发现了这个问题,不知道是bug还是设计如此,所以提了个issue

看了下源码,设置绑定值其实就是调用了 setCheckedKeys。Tree 组件没有像 Input 组件一样把父组件 inject 进来,不过特别地将 Tree 组件的方法都暴露出来了,我也不清楚算不算 bug。不过有选中的id,直接设置应该能满足需求的,可以看看这个Demo

from element-plus.

JaxonJay avatar JaxonJay commented on May 28, 2024

为什么不直接设置 value 的值呢?
因为返回的数据是所有选中的和半选中的id,用value和v-model都无法正确回显值,所以想着用setCheckedKeys方法的第二个参数设置只设置选中的叶子节点状态
另外其实是可以用别的方法解决的,但是发现了这个问题,不知道是bug还是设计如此,所以提了个issue

看了下源码,设置绑定值其实就是调用了 setCheckedKeys。Tree 组件没有像 Input 组件一样把父组件 inject 进来,不过特别地将 Tree 组件的方法都暴露出来了,我也不清楚算不算 bug。不过有选中的id,直接设置应该能满足需求的,可以看看这个Demo

感谢,我看了这个demo,我补充一下我的应用情况,后端存的时候需要选中的子节点和半选中的父节点的数组,查询的时候自然也是返回了父节点和子节点的id,这样在赋值的时候,直接赋值这个数组,会导致父节点下的所有子节点都被选中,如demo所示,所以想到了用setCheckKeys的第二个参数来保证只有子节点才选中,这样才发现了这个问题的,感觉是在设计的时候没有想到这种情况(这个情况也确实有点极端),但是通过访问实例上的setCheckKeys的时候出现了这个问题,感觉这个组件要么应该适配一下setCheckKeys方法,要么就不暴露这个方法比较好

from element-plus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.