【发布时间】:2019-08-25 20:18:11
【问题描述】:
试图将此数组中的信息获取到组件上!不知道我做错了什么!!请救救我。下面是我的东西
所以我从 firebase 获取我的数据,然后我对它执行此操作
function snapshotToArray(snapshot) {
var returnArr = [];
snapshot.forEach(function(childSnapshot) {
var item = childSnapshot.val();
//item.key = childSnapshot.key;
returnArr.push(item);
});
return returnArr;
};
export function allMyPropertiesDetailsFetch(currentscreen) {
console.log("Called the property details");
const { currentUser } = firebase.auth();
console.log("gotthuser");
console.log(firebase.database().ref(`/properties/`));
var propertyref = firebase.database().ref(`/properties/`).orderByChild('userid').equalTo(currentUser.uid);
propertyref.once('value', snapshot => {
if (snapshot.exists()) {
var Property = snapshotToArray(snapshot);
// console.log('Property: '+Property);
currentscreen.setState({
propertyinfo: Property
});
} else {
// console.log('There is no user who has email like '+ email)
}
})
}
我的数组看起来 [{"aptNumber":"","city":"","nickName":"","numberofbathrooms":"2","numberofbedrooms":"1","state":" ","streetName":"","streetNumber":"","typeof":"Apartment","userid":"sb7Hj93D08XiaRguQ4cbSjz4vXC3"}] 。我这样称呼它仍然不起作用。 var people = JSON.parse(JSON.stringify(this.state.propertyinfo)); console.log(persons);
let added_buttons_goes_here = people.map( (data, index) => { 返回 ( /// 传入删除按钮作为子项的伪代码 this._handleRemoveButton(data.key) } /> ) });
【问题讨论】:
-
请同时添加您的代码。
-
为什么在数组中添加/需要对象键。请删除它
-
发布你的循环逻辑代码...
-
向我展示您的完整代码。当您没有对数组中的键进行排序时,地图将不起作用。
-
请展示您的尝试,以便我们提供帮助。
标签: javascript reactjs react-native