vue Treeselect 下拉树 只能选择第N级元素

今天在项目中遇到一个需求,就是vue下拉树只能选择第三级选项,为了解决这个问题,查阅了官方文档

https://vue-treeselect.js.org/#disable-item-selection

 

然后看到isDisabled属性可以禁止选择,具体实现代码如下:

<treeselect 
   :disable-branch-nodes="true"
   :normalizer="normalizer" 
   v-model="formData.goodsTypeId" 
   :multiple="false" 
   :options="goodsType" 
   placeholder='请选择'>
   <label slot="option-label" slot-scope="{ node, shouldShowCount, count, labelClassName, 
     countClassName }">
          {{ node.label }}
    </label>
</treeselect>

如何给数据添加isDisabled属性呢?

自己尝试着在下拉树配置中添加了一下,竟然成功了

【提示】node这个对象包含的字段打印了一下,(这些数据是后台接口提供的)如下图展示:

【isLeaf】Y是叶子节点,N是分支节点【typeLevel】第?级

normalizer(node) {
   //去掉children=[]的children属性
   if(node.children && !node.children.length) {
      delete node.children;
   }
   if(node.isLeaf=='Y' && node.typeLevel!=3){
      node['isDisabled'] = true;
   }
   return {
      id: node.typeId,
      label: node.typeName,
      children: node.children,
   }             
},

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值