如何解决 Text strings must be rendered within a <Text> in nested map?
How to solve Text strings must be rendered within a <Text> in nested map?
我没有找到解决嵌套地图函数中此错误的方法,我尝试的所有操作都以语法错误告终。
我的代码:
{import codes....}
const FormScreen = ({route}) => {
const [FieldForm, setFieldForm] = useState([]);
const [TypeForm, setTypeForm] = useState([]);
useEffect(() => {
if (FieldForm.length > 0) {
return;
} else {
setFieldForm(JSON.parse(route.params.paramKey).message);
setTypeForm(JSON.parse(route.params.paramKey).tipo);
console.log('SETINGGG',FieldForm,TypeForm);
}
},[FieldForm,TypeForm]);
return (<View>
{FieldForm.length > 0 ? (
FieldForm.map((item) => (
<>
<Text>{`${JSON.stringify(item)}`}</Text>
<>
{TypeForm.map((type) => (
<Text>{`${JSON.stringify(type)}`}</Text>
))}
</>
</>
))
) : (
<Text key={uuid.v4()}> Loading ...</Text>
)}
</View>
我尝试删除这些组件但没有用,我怎样才能让它工作?
您可以使用像 {`${type}`}
这样的模板字符串
我认为您最终会以 [Object]
作为文本正文,但这是开始获取所需值的良好起点。
编辑:`
称为反引号,它们用于创建 template strings
或 string literals
。我们不使用双引号来表示字符串值,而是使用它们。模板字符串能够在其中嵌套对象值并打印它们的字符串表示形式。如果您尝试在模板字符串中打印的只是一个 JSON 对象,您将最终打印 [Object]
。这将告诉你,你实际上并没有打印你想要的对象的值,你可能在 type.value
之后,而是找到你可能正在寻找的对象的 key/value因为,你可以尝试 <Text>{`${JSON.stringify(type)}`}</Text>
.
{TypeForm.map((type) => (
<Text>{`${JSON.stringify(type)}`}</Text>
))}; // remove this ; (dot and comma)
我没有找到解决嵌套地图函数中此错误的方法,我尝试的所有操作都以语法错误告终。
我的代码:
{import codes....}
const FormScreen = ({route}) => {
const [FieldForm, setFieldForm] = useState([]);
const [TypeForm, setTypeForm] = useState([]);
useEffect(() => {
if (FieldForm.length > 0) {
return;
} else {
setFieldForm(JSON.parse(route.params.paramKey).message);
setTypeForm(JSON.parse(route.params.paramKey).tipo);
console.log('SETINGGG',FieldForm,TypeForm);
}
},[FieldForm,TypeForm]);
return (<View>
{FieldForm.length > 0 ? (
FieldForm.map((item) => (
<>
<Text>{`${JSON.stringify(item)}`}</Text>
<>
{TypeForm.map((type) => (
<Text>{`${JSON.stringify(type)}`}</Text>
))}
</>
</>
))
) : (
<Text key={uuid.v4()}> Loading ...</Text>
)}
</View>
我尝试删除这些组件但没有用,我怎样才能让它工作?
您可以使用像 {`${type}`}
我认为您最终会以 [Object]
作为文本正文,但这是开始获取所需值的良好起点。
编辑:`
称为反引号,它们用于创建 template strings
或 string literals
。我们不使用双引号来表示字符串值,而是使用它们。模板字符串能够在其中嵌套对象值并打印它们的字符串表示形式。如果您尝试在模板字符串中打印的只是一个 JSON 对象,您将最终打印 [Object]
。这将告诉你,你实际上并没有打印你想要的对象的值,你可能在 type.value
之后,而是找到你可能正在寻找的对象的 key/value因为,你可以尝试 <Text>{`${JSON.stringify(type)}`}</Text>
.
{TypeForm.map((type) => (
<Text>{`${JSON.stringify(type)}`}</Text>
))}; // remove this ; (dot and comma)