Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 在React中呈现字典数组_Reactjs_Typescript - Fatal编程技术网

Reactjs 在React中呈现字典数组

Reactjs 在React中呈现字典数组,reactjs,typescript,Reactjs,Typescript,我想呈现通过字典分组的数组。但我不能让它工作 我的代码如下所示: var dict: { [key: string] : Array<SomeObject>; }; public render(): React.ReactElement<IProps> { return ( <Container> { this.dict.map((key, idx) => <Row className=

我想呈现通过字典分组的数组。但我不能让它工作

我的代码如下所示:

var dict: { [key: string] : Array<SomeObject>; };

public render(): React.ReactElement<IProps> {
  return (
    <Container>
      {
        this.dict.map((key, idx) =>
          <Row className={styles.dateColumn}>
            <Col sm={12} className={ styles.column }>
            </Col>
          </Row>
        )
      }
    </Container>
  )
}
我希望遍历标题的键,并遍历其数组值以使其位于右标题下

像这样:

- Key 1 
 - Value 1.1 
 - Value 1.2
 - Value 1.3
- Key 2
 - Value 2.1 
 - Value 2.2
 - Value 2.3

您正在使用
string
类型的键和
SomeObject[]
类型的值定义对象

因此,当您编写
this.dict.map
时,Typescript编译器的作用就像您正在使用键
map
访问对象
this.dict
(与
数组
不同,
对象
没有
map
函数)

this.dict.map
返回
SomeObject[]
的值,该值是一个数组而不是一个函数=它不可
调用


您可能会发现,使用一个更适合您所要做的事情。

Wow。是的,完全正确。非常感谢你。有时候JavaScript/TypeScript对于C开发者来说有点棘手D
- Key 1 
 - Value 1.1 
 - Value 1.2
 - Value 1.3
- Key 2
 - Value 2.1 
 - Value 2.2
 - Value 2.3