我正在训练红宝石,我需要做运动,但是我不知道如何获取数据 我有这个
DB = [
{
title: "My first article",
content: "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Id ratione harum illo, dicta minima rerum quod natus cupiditate voluptatibus rem! Amet reprehenderit voluptatum animi, eligendi quia quos reiciendis veritatis magni.",
photo: "https://google.fr",
rating: "2"
},
{
title: "An second article",
content: "Eventually the guys with real ideas not running a scam on the world will overcome. I used an exclamation just to be an asshole and also to make a point! LOL Young Thug is super inspiring to me. Amazing artist!!! I also wanted to point out that it’s the first album to go number 1 off of streaming!!! ",
photo: "https://google.fr",
rating: "2"
},
{
title: "3 article",
content: "also to Kim’s hair and makeup Lorraine jewelry and the whole style squad at Balmain and the Yeezy team. When companies doubt me they doubt us. Wes daytime",
rating: "4"
},
]
COMMENTS = [
["Hello1"],
["comment2"],
["comment3"],
]
我想要这个
DATAS = [ {
title: "My first article",
content: "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Id ratione harum illo, dicta minima rerum quod natus cupiditate voluptatibus rem! Amet reprehenderit voluptatum animi, eligendi quia quos reiciendis veritatis magni.",
photo: "https://google.fr",
rating: "2"
}, ["Hello1"],
....
]
如果可以的话,那将是非常痛苦的,因为对我来说餐桌很难,谢谢
答案 0 :(得分:0)
您没有编写任何代码,所以我不会给您完整的答案。
您可以使用Array#zip
和Array#flatten
获得理想的结果。
flatten
接受一个可选参数,以指定应展平的嵌套数组的数量。
因此DB.zip(COMMENTS).flatten
几乎就是您想要的。您只需要向flatten
提供合适的参数即可。