我有一個物件,它有以下屬性。我想在task array中顯示serialNumber,以便在一個Text元素中顯示。
資料物件 {
"actionTime": null,
"aidedAt": null,
"callPerson": null,
"類別": null,
"contactNo": "0",
"createdAt": "2021-08-06 13:27:55",
"custName1": null,
"custName2": null,
"geoLocation": null,
"id": 1,
"位置": null,
"備注": null,
"重復": null,
"任務": 陣列 [
物件 {
"已完成": false,
"credatedAt": null,
"型號": "Lexmark:MS510DN",
"產品": "PRINTER",
"備注": "卡紙"。
"serialNumber": "451444hh1n1gt",
"狀態": 空。
"主題": "21080295T210",
"ttId": 27226,
"warrantyStatus": "維護_全面"。
},
],
"主題": 空。
}
嘗試了以下方法,但在App上沒有顯示任何東西。
let item = dataOBJ.tasks
console.log("PSerial :",PSerial)
PSerial : 451444HH1N1GT
console.log("iitem : ",item)
iitem : 陣列 [ 物件 { "completed": false, "credatedAt": null, "型號": "Lexmark:MS510DN", "產品": "PRINTER", "備注": "卡紙"。 "serialNumber": "451444hh1n1gt", "狀態": 空。 "主題": "21080295T210", "ttId": 27226, "warrantyStatus": "MAINTENANCE_COMPREHENSIVE", }, ]
const warranty = item.filter(function(item){
return item.serialNumber == PSerial;
}).map(function({warrantyStatus}){
return{warrantyStatus};
});
我想在<Text style={{ fontWeight: 'bold' }}>{item.warrantyStatus}</Text>/code>
uj5u.com熱心網友回復:
如果你的tasks物件內有多個物件,你可以
使用你的warranty函式的邏輯,如下:
item.filter(function(item){
return item.serialNumber == PSerial;
}).map((task,index) => {
回傳(
<文本
key={index}
style={{fontWeight: 'bold' }}}。
>{task.warrantyStatus}</Text>
)})
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/309151.html
標籤:
上一篇:<p>除了<code>render()</code>,<code>handleSubmit()</code>,<code>han
