如何多次渲染一个组件并依次显示结果?
How to render one component multiple times and show the result one after the other?
这就是我想要的:
Jake J.
Matt D.
Kate K.
Matt H.
我得到的是这样的:enter image description here
这是我的代码
renderNames(){
const names =[
"Jake J.",
"Matt D."
...
]
names.map((name,i) = >
return (
<div><b>{name}</b></div>
)
return names;
}
然后在渲染方法中调用 this.renderNames()。名字一个接一个地显示,我不知道我应该怎么做才能一个接一个地显示它们(如上所示)。
我正在使用 Meteor + React + TypeScript。
谢谢
Array.map
doesn't mutate 数组。您的函数 returns 字符串数组,而不是 div 数组。改为这样做:
renderNames(){
const names = [
"Jake J.",
"Matt D.",
...
];
return names.map(name => <div><b>{name}</b></div>);
}
这就是我想要的:
Jake J.
Matt D.
Kate K.
Matt H.
我得到的是这样的:enter image description here 这是我的代码
renderNames(){
const names =[
"Jake J.",
"Matt D."
...
]
names.map((name,i) = >
return (
<div><b>{name}</b></div>
)
return names;
}
然后在渲染方法中调用 this.renderNames()。名字一个接一个地显示,我不知道我应该怎么做才能一个接一个地显示它们(如上所示)。 我正在使用 Meteor + React + TypeScript。
谢谢
Array.map
doesn't mutate 数组。您的函数 returns 字符串数组,而不是 div 数组。改为这样做:
renderNames(){
const names = [
"Jake J.",
"Matt D.",
...
];
return names.map(name => <div><b>{name}</b></div>);
}