首页 文章

ES6插值

提问于
浏览
-1

我有一个配置文件Abc.js

export const config = {
  name:'Name',
  rollNo: 'Roll Number'
}

export const name = {
  london  :'london',
  newYork :'newYork'
}

export const rollNo = {
  1:'one',
  2: 'two'
}

然后,我有一个组件,我在使用此配置文件:

import * as configuration from 'Abc';

Object.keys(configuration.config).map(key,index)
  return (
    <tr key={index}>
    <td><Field name={`${key}`} id={`${key}`}
    options={configuration.${key}}
    />  
   </tr>
   </td>
)

我想在选项中插入键,以便如果键是名称,我想从 Abc.js 读取 configuration.name

谁能告诉我插入这个的方法 .

1 回答

  • 0

    这里不需要使用字符串插值:

    Object.keys(configuration.config).map((key, index) => (
      <tr key={ index }>
        <td>
          <Field name={ key } id={ key } options={ configuration[key] } />  
        </td>
      </tr>
    ));
    

相关问题