VueX Getter可以过滤数组中的唯一ID

时间:2018-08-07 11:00:48

标签: vue.js vuejs2 vuex getter

我想过滤一个数组(包含对象),以获取每个包含唯一correspondence_id的消息。

**商店包含“消息”(具有此结构): enter image description here

Getters 我要过滤的位置。

getCorrespondedUsers: (state) => {
        return state.messages.unique
    }

所有消息都包含correspondence_id,但是现在我只能抓取所有消息,但是我只想抓取唯一的人。这样做的目的是让我有消息,但在左侧我想显示我已发消息的每个人(但是我不确定如何只显示一次每个人)。

如何过滤邮件,使其仅返回带有唯一的correspondence_id的邮件?

2 个答案:

答案 0 :(得分:3)

您可以使用lodash来维护代码的可读性。示例:

// don't forget to import only what
// you really need, not the whole library
import uniqBy from 'lodash/uniqBy'

export default {
  getCorrespondedUsers: state => uniqBy(state.messages, 'correspondence_id')
}

答案 1 :(得分:2)

此问题有solution

因此您可以这样做:

from multiprocessing import Pool,Process
import requests

def get_link_info(url):
    r = requests.get(url, params)
    t = r.text
    return(t)


list_of_urls = [url1, url2, url3, ....]

pool = Pool(processes = 100)
result = pool.map(get_link_info,list_of_urls)

我测试了here

我希望它能起作用!