字符串出现异常行为时在阵列 - 世博会应用

问题描述 投票:0回答:1

我知道这只是几行代码,但据我所知,这是独立于项目的其余部分。然而有人认为更多的上下文将是有益的,我可以发布更多的代码。而现在的问题,奇怪的是我所见过在这么多年作为一名JavaScript开发。

请帮忙

没有任何理由,这两个语句会有所不同?

require('./themes/'+'purple'+'.json');
require('./themes/'+['purple'][0]+'.json');

第一条语句的工作,但第二个做到这一点:

enter image description here

我也试过这样:

require('./themes/'+['purple'].pop()+'.json');

和调试我尝试这样做:

'./themes/'+'purple'+'.json' === './themes/'+['purple'][0]+'.json' // returns true

我不明白这是怎么可能的。我需要能够从主题的数组中选择一个主题。

javascript node.js expo
1个回答
0
投票

鉴于你的代码,我会按名称出口每一个主题,像这样一个文件:

主题/ index.js:

import blueTheme from `./blue.json`
import purpleTheme from `./purple.json`

export { blueTheme, purpleTheme }

然后分别按名称别处导入每个主题:

App.js:

import { purpleTheme } from './themes'
© www.soinside.com 2019 - 2024. All rights reserved.