You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.8 KiB

父节可选中的树

props结构

    type: "bi.custom_tree",
    expander: {
        type: "bi.select_tree_expander",
        isDefaultInit: false,
        el: {},
        popup: {
            type: "bi.custom_tree",
        },
    },
    el: {
        type: "bi.button_tree",
        chooseType: 0,
        layouts: [
            {
                type: "bi.vertical",
            },
        ],
    },
    items: []

bi.expander的el触发的事件不会向上传递,因此要采用bi.select_tree_expander bi.select_tree_expander的trigger设置的是"",目的是防止默认的"click"在节点被点击的时候触发展开.

node实现

父节点可选中,只有点击展开收起按钮才可以触发展开收起. 我们需要override掉doClick方法,因为NodeButton中默认的doClick会调用setOpened方法.

之后需要主动监听展开收起按钮的点击事件,依据当前节点的isOpen()来调用triggerCollapsetriggerExpand方法 注意展开收起按钮要阻止冒泡,不然点击的时候会触发整个节点的选中

    setOpened: function (b) {
        Node.superclass.setOpened.apply(this, arguments);
        //  额外的自定义处理,如加号变成减号,三角箭头由→改为↓
    },

    handleButtonClick: function () {
        this.isOpened() ? this.triggerCollapse() : this.triggerExpand();
    },

    doClick: function () {
        // 很重要
    }

item实现

子节只涉及选中业务,不涉及展开收起业务,所以直接继承BasicButton即可,无需override任何方法

其他公共实现

  1. 可以手动实现getValue方法,或者在构建items生成value属性
  2. 选中样式可以采用bi-list-itembi-list-item-activebi-list-item-active2bi-list-item-none等样式