el-tree中在methods中更新数组,html代码中取不到数组中该下标的值。

比如,我需要通过一个点击事件使该叶子包含的数据隐藏或者是显示,一般通过数组[index]来实现,但是最开始是不知道数组长度的,这就需要在点击的时候给数组赋值,然后即时更新该数组下标的值,控制它的隐藏或显示。

实现效果:

需要实现在点击自己的叶子时,控制该叶子下的数据改变,其他叶子数据不变,不能影响到其他的叶子。所以需要使用数组,唯一下标。

实现代码:

1.html

<span class="custom-tree-node" slot-scope="{ node, data }">
  <div class="word_style">
    <span>{{ node.label }}</span>
    <img src="../../assets/images2/more.png" @click="clickOperationButt(node,data)">
  </div>
  <div class="operation_style" v-show="showOperationTo[data.id]">
    <p @click="directorySet" :class="{‘active‘: cur == 1}">目录设置</p>
    <p @click="newSubdirectory" :class="{‘active‘: cur == 2}">新增子目录</p>
    <p @click="whitelistModify" :class="{‘active‘: cur == 3}">修改白名单</p>
    <p @click="LibTableLinkManage" :class="{‘active‘: cur == 4}">库表链接管理</p>
    <p @click="deleted" :class="{‘active‘: cur == 5}">删除</p>
  </div>
</span>

2.js

showOperationTo: [],

clickOperationButt(node,data){
  this.showOperationTo[data.id] = !this.showOperationTo[data.id];
  this.$set(this.showOperationTo, data.id, this.showOperationTo[data.id]);
},

注意:

1.我开始是想的使用this.$forceUpdate();来实现强制更新,数组数据都已经变了,但html代码上就是获取不到,不管用,后来百度发现用set给他赋值,就可以实现动态改变html上的数据显示了。

原文地址:https://www.cnblogs.com/5201314m/p/12326681.html

时间: 2024-08-02 04:23:47

el-tree中在methods中更新数组,html代码中取不到数组中该下标的值。的相关文章

第51讲:Scala中链式调用风格的实现代码实战及其在Spark编程中的广泛运用

今天学习了下scala中的链式调用风格的实现,在spark编程中,我们经常会看到如下一段代码: sc.textFile("hdfs://......").flatMap(_.split(" ")).map(_,1).reduceByKey(_ + _)........ 这种风格的编程方法叫做链式调用,它的实现方法见下面的代码: class Animal {def breathe : this.type = this}class Cat extends Animal

Scala中链式调用风格的实现代码实战及其在Spark编程中的广泛运用之Scala学习笔记-41

package com.leegh.parameterization /** * @author Guohui Li *///由于breathe返回的是this,scala将返回类型推断为Animal,而由于Animal没有eat方法//class Animal { def breathe = this }//class Cat extends Animal { def eat = this } class Animal { def breathe: this.type = this }clas

给一个整形数组,给出一个值,当这个值是数组某些数字的和,求出数组下标的值

Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that

C 语言中的左值和右值。以及对比数组名和指针取数组元素的区别。

左值:出现在赋值符左边的符号有时称为左值. 右值:出现在赋值符右边的符号有时称为右值. 编译器为每个变量分配一个地址(左值),这个地址在编译时可知,而且该变量在运行时一直保存于这个地址.相反,存储于变量中的值(它的右值)只有在运行时才可知.如果需要用到变量中存储的值,编译器就发出指令从指定地址读入变量值并将它存于寄存器. 可以看到,每个符号的地址在编译时可知. 对比一下几个式子: //常规变量 int a=1;//这里a作为左值出现,代表的是地址,即在a表示的这个内存地址存入数值1.即a代表的内

Xcode 6 beta3 中 Swift 的若干更新(转载)

Xcode 6 beta3 对Swift 自从公布以来的第一次比较大的更新,尤其是对数组的更新,主要体现在几个方面:1.数组被重写,现在声明为 let 的数组为不可变数组,声明为var 的是可变的2.声明数组和字典的语法糖也作了修改, 原来声明数组:Int[] 改为 [Int] ,同样的, 字典声明方式变为  [Key: Value]:3.区间运算符 .. 不再使用,而用  ..< 替代,使语意更明确. Xcode 6 beta3 中 Swift 的若干更新(转载)

vue中数据更新视图不更新的问题

遇到这样一个问题, 代码如下: this.memberLevelList.forEach(item => { item.levelDate = [item.startTime, item.endTime]; }) startTime和endTime是从后台获取的数据, 但是模板中需要levelDate, 于是直接赋值, 最后打印的memberLevelList结果中也有levelDate的数据, 但是页面上始终不渲染; 看了一下memberLevelList的observer(观察者), 发现并

本程序找出字符串数组 String[] arr = {“welcome”, “china”, “hi”, “congratulation”, “great”} 中的长度最大的元素,并打印输出。

/** * Homework14 * * @Description:本程序找出字符串数组 String[] arr = {"welcome", "china", "hi", * "congratulation", "great"} 中的长度最大的元素,并打印输出. * StringDemo01 * * @author  * * email: [email protected] 2017年4月18日下午6:3

编程算法 - 数组中只出现一次的数字 代码(C)

数组中只出现一次的数字 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 一个整型数组里除了两个数字以外, 其他的数字都出现了两次. 请写程序找出这两个只出现一次的数字. 如果从头到尾依次异或数组中的每一个数字, 那么最终的结果刚好是那个只出现一次的数字. 根据结果数组二进制某一位为1, 以此分组, 为1的一组, 为0的一组, 再重新进行异或. 最后得出两个结果. 时间复杂度O(n). 代码: /* * main.cpp * * Create

编程题:指针输出数组的灵活性。功能:输出数组中全部元素

#include<stdio.h> void main() { int *p,i; int a[5]={1,2,3,4,5}; p=a; printf("\n"); for(;p<a+5;p++) printf("%d\t",*p); } 编程题:指针输出数组的灵活性.功能:输出数组中全部元素,布布扣,bubuko.com