亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 React Native-JavaScript 中將布爾值轉換為字符串

在 React Native-JavaScript 中將布爾值轉換為字符串

米琪卡哇伊 2023-03-03 10:19:22
所以,我在做一個 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我如何獲得該結果?我試過使用replaceFunction 將 true/false 替換為 Yes/No,但它不起作用。我知道我必須先做一個函數,但我不知道怎么做。任何幫助將不勝感激。謝謝
查看完整描述

2 回答

?
慕桂英546537

TA貢獻1848條經驗 獲得超10個贊

你試過了嗎:

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


查看完整回答
反對 回復 2023-03-03
?
子衿沉夜

TA貢獻1828條經驗 獲得超3個贊

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>


查看完整回答
反對 回復 2023-03-03
  • 2 回答
  • 0 關注
  • 161 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號