【问题标题】:Convert 1 dimensonal list to 3 dimensional list [closed]将 1 维列表转换为 3 维列表 [关闭]
【发布时间】:2019-11-30 12:14:26
【问题描述】:

我有一个一维列表。我必须将其转换为三维列表。我该如何管理它?

这些是我的清单。

 this.galleryImages = [
            {
                small: 'https://res.cloudinary.com/tasit-com/image/upload/c_thumb,w_640,h_480,e_sharpen:120/ccd97b3bb468f62162e1ce7557f25a06.jpg',
                medium: 'https://res.cloudinary.com/tasit-com/image/upload/c_thumb,w_640,h_480,e_sharpen:120/ccd97b3bb468f62162e1ce7557f25a06.jpg',
                big: 'https://imganuncios.mitula.net/renault_clio_2017_motorin_1_94_vade_orani_40_pe_i_n_48ay_taksi_t_duzgun_ti_caret_bunyesi_nde_3720113557242259227.jpg',

            },
            {
                small: 'https://imganuncios.mitula.net/renault_clio_2017_motorin_1_94_vade_orani_40_pe_i_n_48ay_taksi_t_duzgun_ti_caret_bunyesi_nde_3720113557242259227.jpg',
                medium: 'https://imganuncios.mitula.net/renault_clio_2017_motorin_1_94_vade_orani_40_pe_i_n_48ay_taksi_t_duzgun_ti_caret_bunyesi_nde_3720113557242259227.jpg',
                big: 'https://imganuncios.mitula.net/renault_clio_2017_motorin_1_94_vade_orani_40_pe_i_n_48ay_taksi_t_duzgun_ti_caret_bunyesi_nde_3720113557242259227.jpg'
            },
            {

                small: 'https://www.ihaleden.com/uploads/media/5c6f93d30a4a4.png',
                medium: 'https://www.ihaleden.com/uploads/media/5c6f93d30a4a4.png',
                big: 'https://www.ihaleden.com/uploads/media/5c6f93d30a4a4.png'
            }
        ]

我的一维列表是 selectedFilesList。我想将此列表转换为 3 维列表并与其他列表相等。

【问题讨论】:

  • 3 dimensional 是什么意思?您能否编辑问题以提供所需的结构?
  • 就这样?现在你能帮我哈伦爵士吗?
  • 我的意思是您希望将数组转换为 this.galleryImages['small'][0]this.galleryImages['medium'][2] 而不是 this.galleryImages[0]['small']this.galleryImages[2]['medium']
  • 我有一个一维数组。我想将其转换为 3d 数组,将每个项目重复 3 次
  • 请考虑编辑此问题中的代码以构成minimal reproducible example。这应该包括输入和所需的输出。现在你只有问题中的输出,以及评论中的输入草图。看起来您想要inArr.map(x => ({small: x, medium: x, large: x})),但如果没有实际的示例代码,我们无法确定。祝你好运!

标签: angular typescript


【解决方案1】:

如果我正确理解您的问题,使用map 函数可以帮助您喜欢以下内容:

const selectedFilesList = ['a', 'b', 'c'];

this.galleryImages = selectedFilesList.map((selectedFile) => {
    return {
        small: selectedFile,
        medium: selectedFile,
        big: selectedFile
    }
});

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-30
    • 2021-12-18
    • 1970-01-01
    • 1970-01-01
    • 2022-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多