• 关于Element UI tree组件 懒加载的更新操作


    近期根据需求,要做一个懒加载的组织树,并且可以编辑组织树。但是编辑了之后无法进行实时更新。

    一开始想到了很多解决方案,也在网上参考了很多方案,但是都又种种不足。

    所以我去看了elementUI的tree组件的懒加载方法的源代码

    Node.prototype.loadData = function loadData(callback) {
        var _this5 = this;
    
        var defaultProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
    
        if (this.store.lazy === true && this.store.load && !this.loaded && (!this.loading || Object.keys(defaultProps).length)) {
          this.loading = true;
          
          var resolve = function resolve(children) {
            _this5.loaded = true;
            _this5.loading = false;
            _this5.childNodes = [];
    
            _this5.doCreateChildren(children, defaultProps);
    
            _this5.updateLeafState();
            if (callback) {
              callback.call(_this5, children);
            }
          };
    
          this.store.load(this, resolve);
        } else {
          if (callback) {
            callback.call(this);
          }
        }
      };

    this明显是当前节点, 看if语句的条件中 this.loaded是当前节点是否已加载 。 resolve中把this.loaded置为了true;

    所以只用将当前节点的父节点的loaded属性置为false就行了。 这样再次点击该节点时,会继续请求懒加载方法。

    PS1 : 这里为了更人性化,我将isLeaf和expanded属性也置为了false。

    PS2 : 光修改属性是无法触发视图更新的,这里我通过了vue.$set()方法来触发视图更新。  vue.$set的用法见官方文档:https://cn.vuejs.org/v2/api/#Vue-set

    orgSuccess(){
          //如果是新增子节点,则刷新当前节点 ,如果是更新当前节点,刷新父节点
          let node = this.isNew?this.currentNode:this.currentNode.parent;
          node.loaded=false;
          node.isLeaf = false;
          this.$set(node,'expanded',false);
        },
  • 相关阅读:
    nginx并发数设置_Nginx Ingress 高并发实践
    推荐一个国人开源的推荐系统
    异步并发利器:实际项目中使用CompletionService提升系统性能
    JDK中CompletableFuture类
    mysql日志redo log、undo log、binlog
    <a>标签下载文件 重命名失败 download 无效
    nginx geo黑名单
    夜莺微信报警-V3
    分布式事务的学习
    php实现AES/CBC/PKCS5Padding加密解密(又叫:对称加密)
  • 原文地址:https://www.cnblogs.com/fire-forget/p/12367636.html
Copyright © 2020-2023  润新知