分类 技术相关 下的文章

For Java 8, you can convert the Map into a stream, process it and returns it back as a List

示例代码

package com.test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class ConvertMapToList {

    public static void main(String[] args) {

        Map<Integer, String> map = new HashMap<>();
        map.put(10, "apple");
        map.put(20, "orange");
        map.put(30, "banana");
        map.put(40, "watermelon");
        map.put(50, "dragonfruit");

        System.out.println("\n1. Export Map Key to List...");

        List<Integer> result = map.keySet().stream()
                .collect(Collectors.toList());

        result.forEach(System.out::println);

        System.out.println("\n2. Export Map Value to List...");

        List<String> result2 = map.values().stream()
                .collect(Collectors.toList());

        result2.forEach(System.out::println);

        System.out.println("\n3. Export Map Value to List..., say no to banana");
        List<String> result3 = map.keySet().stream()
                .filter(x -> !"banana".equalsIgnoreCase(x))
                .collect(Collectors.toList());

        result3.forEach(System.out::println);

    }

}

输出

1. Export Map Key to List...
50
20
40
10
30

2. Export Map Value to List...
dragonfruit
orange
watermelon
apple
banana

3. Export Map Value to List..., say no to banana
dragonfruit
orange
watermelon
apple

假设一个nodes列表,想在点击节点的时候控制子节点的显示和隐藏,此时需要添加一个“显示内容”属性来控制。

核心代码如下:

this.$set(this.nodes[index],'showContent',result)

参考代码:

     controlDis(index){//通过index拿到当前值
        let result = false;
        if(!this.nodes[index].showContent){
          result = true;
        }
        this.$set(this.nodes[index],'showContent',result)
      }

经测试,新属性的值能立即控制页面的显示和隐藏。

mpvue 使用微信小程序组件scroll-view的方法

  1. <scroll-view :style="{'height': '300px'}"></scroll-view>要设置高度
  2. 举例:小程序原先方法是bindscrolltolower,在mpvue当中要写成@scrolltolower template

template 代码

<scroll-view  :style="{'height': '200px'}" :scroll-y="true" @scrolltolower="scrolltolower" @scroll="scroll" >
  <div :style="{'height': '200px','background-color':'red'}">tyuiolpo</div>
  <div class=""  :style="{'height': '200px','background-color':'red'}">测试测试
  </div><div class=""  :style="{'height': '200px','background-color':'red'}">测试内容内容</div>
</scroll-view>

methods 部分

methods: {
    scrolltolower(){
      console.log(7)
    },
    scroll(e) {
      console.log(6)
      console.log(e)
    }
 }
免责声明
本博客部分内容来自于互联网,不代表作者的观点和立场,如若侵犯到您的权益,请联系[email protected]。我们会在24小时内进行删除。