【问题标题】:I want to rename value of JSON File to readable Text with key/value in angular 2+我想将 JSON 文件的值重命名为 angular 2+ 中键/值的可读文本
【发布时间】:2019-11-25 18:24:57
【问题描述】:

我有一个包含一些数据的数据表,单击任何一行我们都会获得一些详细信息,详细信息来自 JSON 文件,我想用键值重命名该值。因为数据看起来像“some_information”,我想展示一些像“Some information”这样的东西

我在想我可以在子组件中使用 map,或者在子 html 文件中使用 ngSwitch Loop。但它不起作用。

Working Stuff here

【问题讨论】:

    标签: javascript angular key-value


    【解决方案1】:

    在分配dataSource之前,您可以执行以下操作来修改name的值:

    ELEMENT_DATA.forEach(el => {
      // first we replace any '_' with an empty space
      // then we capitalize each first letter of `name` words.
      let modifiedName = el.name.replace(/\_/g, ' ');
      modifiedName = modifiedName.charAt(0).toUpperCase() + modifiedName.slice(1);
      el.name = modifiedName;
    })
    

    【讨论】:

      猜你喜欢
      • 2016-09-23
      • 2023-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-21
      • 1970-01-01
      • 2021-01-08
      • 2020-04-09
      相关资源
      最近更新 更多