Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

动态加载的tree数据 设置默认的时候失效,不能默认选中,大家有遇到这个问题吗 #9

Open
lingdayan opened this issue Jun 24, 2019 · 2 comments

Comments

@lingdayan
Copy link

动态加载的tree数据 设置默认的时候失效,不能默认选中,大家有遇到这个问题吗

@canyuegongzi
Copy link

是的,我也遇到了,你解决了吗?

@luwzchn
Copy link

luwzchn commented Sep 5, 2019

@lingdayan @canyuegongzi

watch改成如下:

watch: {
    value() {
      this.valueId = this.value;
      this.initHandle();
    },
    options: {
      handler(newValue, oldValue) {
        this.valueId = this.value;
        this.initHandle();
      },
      deep: true
    }
  },

methods 里面 initHandle函数改成如下:

// 初始化值
    initHandle() {
      if (this.valueId) {
        this.$nextTick(() => {
          let node = this.$refs.selectTree.getNode(this.valueId);
          if (node != null) {
            this.valueTitle = node.data[this.props.label]; // 初始化显示
            this.$refs.selectTree.setCurrentKey(this.valueId); // 设置默认选中
            this.defaultExpandedKey = [this.valueId]; // 设置默认展开
          }
        });
      } else {
        this.valueTitle = ""; // 清除缓存显示
      }
      this.initScroll();
    },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants