在 React Native 中将布尔值转换为字符串-JavaScript

Boolean into String in React Native-JavaScript

所以,我在做一个 React Native 项目,我有一个这样的复选框:

      import ARCheckBox from '@react-native-community/checkbox';
      .............
      <View style={styles.row}>
      <Text style={styles.label}>Insured Interest</Text>
         <Text>Section IV - AutomobileLiability</Text>
         <ARCheckBox
          value={this.state.arCBValue3}
          onValueChange={value =>
            this.setState({
              arCBValue3: value,
            })
          }
        />
      </View>

这是我的 .js 输出:

import { style } from "./../../../reports/ARCssPdf";

export const arGenerateFileHtml = values => {
  return`
  ${style}
  ${generateNameSectionHtml(values)}`;
};

const generateNameSectionHtml = name =>
`<html>
<head>
</head>
    <br/>
<body>
  <div>
      <table style="width:450px">
      <tr>
      <td> Section IV - AutomobileLiability</td>
      <th> : </th>
      <th> ${name.arCBValue3}</th> //This is the output
      </tr>
  </table>
</div>
</body>
</html>`

但是我得到的结果是这样的:

Section IV - AutomobileLiability : true/false

虽然我想要的结果是这样的:

Section IV - AutomobileLiability : Yes/No

我如何获得该结果?我尝试使用 replace 函数将 true/false 替换为 Yes/No,但它不起作用。我知道我必须先做一个函数,但我不知道怎么做。任何帮助将不胜感激。谢谢

你试过了吗:

   <th> ${name.arCBValue3 ? 'Yes':'No'}</th>

import {
  style
} from "./../../../reports/ARCssPdf";

export const arGenerateFileHtml = values => {
  return `
  ${style}
  ${generateNameSectionHtml(values)}`;
};
const replacer = value => value ? "Yes" : "No"
const generateNameSectionHtml = name =>
  `<html>
<head>
</head>
    <br/>
<body>
  <div>
      <table style="width:450px">
      <tr>
      <td> Section IV - AutomobileLiability</td>
      <th> : </th>
      <th> ${replacer(name.arCBValue3)}</th> //This is the output
      </tr>
  </table>
</div>
</body>
</html>`
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>