javascript - 在 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
Function 将 true/false 替换为 Yes/No,但它不起作用。我知道我必须先创建一个函数,但我不知道如何。任何帮助将不胜感激。谢谢
解决方案
你试过了吗:
<th> ${name.arCBValue3 ? 'Yes':'No'}</th>
推荐阅读
- sql - Sql 参数默认值
- python - 从 Django Admin 表单中的 DateField 中删除多余的字符
- swift - 在 Swift 4.1 中编译的模块不能在 Swift 4.0.3 中导入
- python - 列长度可以是小数吗
- ios - 使用tableView的titleForHeader的dateformatter从字符串转换日期但得到零错误
- php - 如何反转 WordPress 评论分页
- react-native - 如何在 React Native Navigation wix V1 中单击时关闭抽屉
- python - Cocos2d / Python中奇怪的虚线
- c++ - 使用 curl_easy_cleanup(curl) 时收到未处理的 NULL 异常
- javascript - “完成”一个 rxjs 主题的目的是什么?