我有以下对象,每次我调用object [“ key”]时,由于某种原因它返回undefined
我尝试了以下操作,但仍未定义
<SectionList
renderItem={({item, index, section}) =>
// render the entire item in the `renderItem` call with one `TouchableOpacity`
<TouchableOpacity onPress={ () => this.onPressOrder(item.id) }>
<View>
<Text>
{item.inspector}
</Text>
</View>
<View>
<Text>
{item.inspection_date}
</Text>
</View>
... etc.
</TouchableOpacity>
}
renderSectionHeader={({section: {title}}) => (
<Text style={{fontWeight: 'bold'}}>{title}</Text>
)}
sections={this.state.dataSource}
keyExtractor={item => item.id}
/>
dataSource.push({
// each section just has one list item that is the full list item
data: [
listItem,
],
key: keyId,
title: listItem.address
})
所有人都返回未定义
object.keyName
object[keyName]
object["keyName"]
让我说我想要placeName值 我尝试过
let sam = {
"facebook": "https://facebook.com",
"instagram": "https://Instagram.com",
"placeName": "dazzlement",
"snapchat": "https://snapchat.com",
"twitter": "https://twitter.com",
}
全部返回未定义。
--------更新----------
我在Parse JS SDK中使用本机反应,这是用于从Parse数据库获取值并将其作为道具发送到组件的代码,该组件将结果显示为卡片
sam.placeName
sam[placeName]
sam["placeName"]
在组件中是代码
this.state = {
items: null,
loaded: false
};
componentDidMount() {
this.queryValues()
}
queryValues = async id => {
let cy = this;
const GameScore = Parse.Object.extend('social');
const query = new Parse.Query(GameScore);
query.equalTo('A', 1);
query.equalTo('B', 2);
const results = await query.find().then(
results => {
cy.setState({
items: results
loaded: true,
})
},
error => {}
);
};
render() {
return (
{
this.state.loaded ?
<FlatList
data = {this.state.items}
renderItem = {
({item}) => <SocialCard social={item} /> } /
>
: <
Text> Loading </Text>
}
);
}
}
日志显示如下
render() {
const {
social
} = this.props;
console.log(social)
return (
<Text>{this.props.}</Text>
);
}
答案 0 :(得分:0)
这应该返回所有链接
let sam = {
facebook: 'facebook.com', // you don't need " " for facebook
instagram: 'instagram.com'
}
for (let i in sam){
console.log(sam[i])
}
sam.facebook // facebook.com
sam.instagram // instagram.com