我正在使用react-native-google-places根据用户输入获取结果。
我可以基于自动完成的用户输入来控制台记录搜索结果,但是不会在我的自定义列表视图中返回该值。
代码
export function getAddressPredictions(){
return(dispatch, store)=>{
let userInput = store().home.resultTypes.pickUp ? store().home.inputData.pickUp : store().home.inputData.dropOff;
RNGooglePlaces.getAutocompletePredictions(userInput,
{
country:"IND"
}
)
.then((results)=>
dispatch({
type:GET_ADDRESS_PREDICTIONS,
payload:results
})
)
.catch((error)=> console.log(error.message));
};
}
function handleGetAddressPredictions(state, action){
return update(state, {
predictions:{
$set:action.payload
}
})
}
const ACTION_HANDLERS = {
GET_ADDRESS_PREDICTIONS:handleGetAddressPredictions
}
这是自定义列表视图,用于根据用户输入在中显示搜索。
export const SearchResults = (predictions)=>{
return (
<View style={styles.searchResultsWrapper} >
<List
dataArray={predictions}
renderRow={(item)=>
<View>
<ListItem button avatar>
<Left style={styles.leftContainer}>
<Icon style={styles.leftIcon} name="location-on" />
</Left>
<Body>
<Text style={styles.primaryText}>{item.primaryText}</Text>
<Text style={styles.secondaryText}>{item.secondaryText}</Text>
</Body>
</ListItem>
</View>
}
/>
</View>
);
}
export default SearchResults;
上面的代码正确地获取了控制台日志中的详细信息,但是我无法在列表视图中返回值。
如果我用硬编码文本替换 {item.primaryText} ,则会显示该文本。
日志文件
{home: {…}}
home:
inputData: {pickUp: "drive"}
predictions: Array(5)
0: {types: Array(2), placeID: "EkBEcml2ZSBJbiBSb2FkLCBTdW5yaXNlIFBhcmssIE1lbW5hZ2…6z6yEXjkRMJeafp9UzlASFAoSCYfkscixhF45ESTcwBLlzE9c", secondaryText: "Sunrise Park, Memnagar, Ahmedabad, Gujarat, India", primaryText: "Drive In Road", fullText: "Drive In Road, Sunrise Park, Memnagar, Ahmedabad, Gujarat, India"}
1: {types: Array(4), placeID: "ChIJ4dTf1U1mUjoRSSPy-3Y49qk", secondaryText: "Chennai, Tamil Nadu, India", primaryText: "Drivers Colony, T Nagar", fullText: "Drivers Colony, T Nagar, Chennai, Tamil Nadu, India"}
2: {types: Array(4), placeID: "ChIJRWoDFq6EXjkRCmo7r2rn_xw", secondaryText: "Sunrise Park, Gurukul, Ahmedabad, Gujarat", primaryText: "Drive In Cinema", fullText: "Drive In Cinema, Sunrise Park, Gurukul, Ahmedabad, Gujarat"}
3: {types: Array(4), placeID: "ChIJlaOzFK6EXjkR86sdRNqJgqY", secondaryText: "Nilmani Society, Thaltej, Ahmedabad, Gujarat", primaryText: "Drive In Cinema", fullText: "Drive In Cinema, Nilmani Society, Thaltej, Ahmedabad, Gujarat"}
4: {types: Array(1), placeID: "ChIJiVzj_YiUyzsRHgB632DAI44", secondaryText: "Financial District, Gachibowli, Hyderabad, Telangana, India", primaryText: "Driven Cafe", fullText: "Driven Cafe, Financial District, Gachibowli, Hyderabad, Telangana, India"}
length: 5
__proto__: Array(0)
region: {}
resultTypes: {pickUp: true, dropOff: false}
预期结果-位置应显示在列表视图中。