将 object 文字从函数传递到 json 数组

pass object literal from function into json array

我有一个 javascript 函数来创建本地化字符串,如下所示...

let strings = new LocalizedStrings({
 en:{
   sites:"Sites",
   addSite:"Add a new site",
   online:"Online"
 },
 it: {
    sites:"Siti",
   addSite:"Aggiungi un nuovo sito",
   online:"in linea"
 }
});

我在我的页面中这样使用它..

<p>
  {strings.sites}
</p>

我的问题是如何将它传递到我的 JSON 中,因为我需要更新我的 table 中的列标题,它使用 JSON 来定义它(请参阅 'name' 标题)...

const columns = [
    {
        name: 'Id',
        selector: 'id',
        sortable: true,
        hide: 6000,
    },
    {
        name: '{strings.online}',
        selector: 'cloudAccessEnabled',
        sortable: true,
        minWidth: '10px',
        center: true,
        cell: row => (
            <MDBIcon icon="circle"
                className={row.cloudAccessEnabled === true ? 'green-text' : 'red-text'} />
        )
    },

我怀疑像 strings.online 这样没有引号或大括号的东西应该可以工作。 或者调用函数 strings.getString("online")

但这只是一个假设,因为我认为你使用的是 React 但我不确定。