首页 > web前端 > js教程 > vue Treeselect树形下拉框之获取选中节点的ids和lables操作

vue Treeselect树形下拉框之获取选中节点的ids和lables操作

coldplay.xixi
发布: 2020-08-17 17:15:49
转载
4690 人浏览过

vue Treeselect树形下拉框之获取选中节点的ids和lables操作

【相关学习推荐:js视频教程

API: https://vue-treeselect.js.org/#events

1.ids: 即value

1.lable: 需要用到方法:@select(node,instanceId) 和 @deselect(node,instanceId)

<template>
<treeselect ref="DRHA_EFaultModeTree"
    v-model="DRHA_EFaultModeTree_value"
    :multiple="true" 
    :options="DRHA_EFaultModeTree_options"
    :flat="true"
    :show-count="true"
    :disable-branch-nodes="true"
    :searchable="false"
    @select="DRHA_EFaultModeTree_handleSelect"
    @deselect="DRHA_EFaultModeTree_handleDeSelect"
    placeholder=" 请选择..."/>
 
 <p>lables:{{DRHA_EFaultModeTree_lables}}</p>
 <p>ids:{{DRHA_EFaultModeTree_value}}</p>
 
</template>
 
<script>
 // import the component
 import Treeselect from &#39;@riophae/vue-treeselect&#39;
 // import the styles
 import &#39;@riophae/vue-treeselect/dist/vue-treeselect.css&#39;
 
 
 export default {
 components: { Treeselect },
 data() {
  return {
  
  DRHA_EFaultModeTree_value: null,
  DRHA_EFaultModeTree_lables: [],
  DRHA_EFaultModeTree_options: [ {
   id: &#39;1&#39;,
   label: &#39;Fruits&#39;,
   children: [ {
   id: &#39;1-1&#39;,
   label: &#39;Apple ?&#39;,
   isNew: true,
   }, {
   id: &#39;1-2&#39;,
   label: &#39;Grapes ?&#39;,
   }, {
   id: &#39;1-3&#39;,
   label: &#39;Pear ?&#39;,
   }, {
   id: &#39;1-4&#39;,
   label: &#39;Strawberry ?&#39;,
   }, {
   id: &#39;watermelon&#39;,
   label: &#39;Watermelon ?&#39;,
   } ],
  }, {
   id: &#39;vegetables&#39;,
   label: &#39;Vegetables&#39;,
   children: [ {
   id: &#39;corn&#39;,
   label: &#39;Corn ?&#39;,
   }, {
   id: &#39;carrot&#39;,
   label: &#39;Carrot ?&#39;,
   }, {
   id: &#39;eggplant&#39;,
   label: &#39;Eggplant ?&#39;,
   }, {
   id: &#39;tomato&#39;,
   label: &#39;Tomato ?&#39;,
   } ],
  } ],
  };
 },
 mounted: function(){
  
 },
 methods: {
  DRHA_EFaultModeTree_handleSelect(node,instanceId){
  console.log("Select");
  this.DRHA_EFaultModeTree_lables.push(node.label);
  },
  DRHA_EFaultModeTree_handleDeSelect(node,instanceId){
  console.log("DeSelect");
  for (let i = 0;i<this.DRHA_EFaultModeTree_lables.length;i++){
   if(node.label == this.DRHA_EFaultModeTree_lables[i]){
   this.DRHA_EFaultModeTree_lables.splice(i,1);
   }
  }
  },
 }
 };
</script>
登录后复制

补充知识:vue Treeselect 下拉树选择 问题总结

情况:

解决方法:

截图:

问题二:只能选择最小分类

如图:

问题三:显示 分类的个数

相关学习推荐:编程视频

以上是vue Treeselect树形下拉框之获取选中节点的ids和lables操作的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
vue
来源:jb51.net
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板