![](/img/trans.png)
[英]How do I sustain data from DB while using another GET request with different query string in React(Next.js)?
[英]How to get data from DB when a string is in another string?
我試圖從我的工作對象中獲取位置字段,但是例如當我放置location.address
,它似乎在js中語法錯誤。
這是我的常量,除了地址,城市和郵政編碼外,其他所有內容都可以正常工作。
const { title, avatar, company, postDate, jobType, payment, duration, description, address, city, postcode } = this.props.navigation.state.params;
這是我的數據庫方案
jobs: [{
title: {type: String},
company: {type: String},
avatar: {type: String},
created: {type: Boolean},
applied: {type: Boolean},
description: {type: String},
location: [{
address: {type: String},
postcode: {type: String},
city: {type: String}
}],
jobType: {type: String},
payment: {type: String},
duration: {type: String},
postDate: {type: Date},
expDate: {type: Date}
}]
location
是那里的一array
對象。 您必須使用一些循環來訪問它的屬性,例如
location.forEach(e=>console.log(e.address))
這可能是你的表情
const { title, avatar, company, postDate, jobType, payment, duration, description, location } = this.props.navigation.state.params;
您不能在數組上點。
您的地址嵌套在數組內。
location: [{
address: {type: String},
postcode: {type: String},
city: {type: String}
}]
要訪問它,您需要像這樣對其進行索引
jobs[0].location[0].address
location是一個數組。 假設每個數據的位置都是單例的,則不必數組。 更換
...
location: [{
address: {type: String},
postcode: {type: String},
city: {type: String}
}],
...
至
...
location: {
address: {type: String},
postcode: {type: String},
city: {type: String}
},
...
只需使用location.address
但它應該是一個數組,像處理數組一樣使用它
對於第一個元素
location[0].address
對於第二元素
location[1].address
對於所有元素
location.forEach(varName){
varName.address
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.