地图内的多个三元运算符

multiple ternary operator inside a map

我的 api 回复是 returns 7 个不同号码中的 1 个。这些数字中的每一个都代表一个不同的词。 (1 = 完成,2 = 待定等)

我的问题是要获得我必须映射到 api 上的数字,所以我最终得到类似

的结果
<p>{item.apiNumber}</p>

所以我的问题是如何获取 api 地图中返回的数字并根据它显示文本?

我尝试 运行 映射中的 if 语句和 setState,但没有用。

我尝试了一个三元组,没问题,但我还需要 6 个。

您可以在组件内部创建方法,该方法将分析 apiNumber 并将 return 根据文本。在您的段落中,您只需调用该方法:

getApiTextByNumber(number) {
  switch (number) {
    /*return appropriate text here*/
  }
}
...
<p>{this.getApiTextByNumber(item.apiNumber)}</p>