小编Neu*_*ode的帖子

用Java干净地初始化带有特定数据集的字典

我很好奇如何才能更有效地实例化Java中的字典。目前,我有可传递的代码,但是我以一种非常模糊的方式填充数据。

有什么办法可以像这样初始化字典吗?记录的是python:

westernCanadaAdjList =  {  'BC': ['AB'],
                       'AB': ['BC', 'SK'],
                       'SK': ['AB', 'MB'],
                       'MB': ['SK']
                        }
Run Code Online (Sandbox Code Playgroud)

我发现出于演示目的,这一点要清晰得多。

我当前在Java中的代码:

public class Main {

public static void main(String[] args) {

    //Adjacency List representation through a dictionary. Allows fast O(1) lookup time.
    Map<String,ArrayList<String>> adjList = new HashMap<String,ArrayList<String>>();


    //Adding values for Edmonton
    adjList.put("Edmonton", new ArrayList<String>());
    adjList.get("Edmonton").add("Neighbour1");
    adjList.get("Edmonton").add("Neighbour2");
    adjList.get("Edmonton").add("Neighbour3");


    //Adding values for Vancouver
    adjList.put("Vancouver", new ArrayList<String>());
    adjList.get("Vancouver").add("V neighbour1");
    adjList.get("Vancouver").add("V neighbour2");

    System.out.println(adjList.keySet() +" And Values " +  adjList.values());

    for (String neighbour: adjList.get("Edmonton")){
        System.out.println(neighbour);
    }

    for (String …
Run Code Online (Sandbox Code Playgroud)

java dictionary initialization

5
推荐指数
2
解决办法
6642
查看次数

React-Markdown自定义组件声明,如何在渲染器中声明使用自定义组件?

问题

使用 React-Markdown,我可以充分使用我的自定义构建组件。但这是在降价中使用特定的预先构建的关键字。像段落或图像。效果非常好。但问题是,这些似乎都是预先构建的单词/条件,如段落、标题或图像。

我找不到在我的降价中添加新关键字的方法,例如要使用的“CustomComponent”。这就是我现在所需要的><

这对我来说很好用,可以将降价图像制作成我在其他地方制作的自定义“页脚”组件。我知道这很荒谬,但它确实有效。但我不知道如何让这个渲染器接受/创建一个新的关键字,如“emoji”或“customComponent”或“somethingSilly”。

let body = 
    `![Fullstack React](https://dzxbosgk90qga.cloudfront.net/fit-in/504x658/n/20190131015240478_fullstack-react-cover-medium%402x.png)`;

const renderers = {
    image: () => <Footer/>
};

<ReactMarkdown source={body} renderers={renderers} />;
Run Code Online (Sandbox Code Playgroud)

我过去做过的一些工作:

一些文档: https://reposhub.com/react/miscellaneous/rexxars-react-markdown.html https://github.com/rexxars/commonmark-react-renderer/blob/master/src/commonmark-react-renderer。 js#L50

示例: https: //codesandbox.io/s/react-markdown-with-custom-renderers-961l3 ?from-embed=&file=/src/App.js

但没有任何内容表明我如何使用“CustomComponent”来指示注入自定义组件。

用例/背景

我正在尝试从我的数据库中检索一篇文章,该文章的格式类似于 Markdown 中的格式(基本上是一个巨大的字符串)。我正在使用 typescript 和 redux 进行常规反应——这是我的应用程序中唯一需要它的部分。

"
# Title

## Here is a subtitle

Some text

<CustomComponentIMade/>

Even more text after.


<CustomComponentIMade/>

"
Run Code Online (Sandbox Code Playgroud)

javascript markdown typescript reactjs react-markdown

3
推荐指数
1
解决办法
3074
查看次数

如何更改材质 ui 选择菜单的下拉颜色?

我只想更改下拉菜单背景颜色的颜色,但我尝试的任何操作都不起作用,我感到困惑。

我没什么可说的了,stackoverflow 希望我添加更多文本,但我只能说我一直在谷歌上搜索各种解决方案,但到目前为止没有任何效果。

const BootstrapInput = withStyles((theme: Theme) =>
    createStyles({
        root: {
            'label + &': {
                marginTop: theme.spacing(3),
            },
        },
        selectMenu: {
            color: 'rgba(1,1,255,1)',
            backgroundColor: "#rgba(255,0,0,1)",
            "& ul": {
                backgroundColor: "#rgba(255,0,0,1)",
            },
            "& li": {
                backgroundColor: "#rgba(255,0,0,1)",
                fontSize: 12,
            },
        },
        input: {
            borderRadius: 0,
            position: 'inherit',
            backgroundColor: 'rgba(0,0,0,0)',
            color: 'rgba(255,255,255,1)',
            border: '1px solid rgba(255,255,255,0.2)',
            fontSize: 15,
            padding: '10px 26px 10px 12px',
            transition: theme.transitions.create(['border-color', 'box-shadow']),
            // Use the system font instead of the default Roboto font.
            fontFamily: [
                '-apple-system',
                'BlinkMacSystemFont', …
Run Code Online (Sandbox Code Playgroud)

reactjs material-ui

2
推荐指数
1
解决办法
6473
查看次数