TypeError: undefined 不是对象 (evlauning 'newData[0].flag')



我集成了一个名为rn country picker的依赖项,并在我的react原生应用程序中使用。它以前工作得很好,但现在它抛出了错误";TypeError:undefined不是对象(evlauating'newData[0].flag'(;我想不出这个错误的确切原因。

我使用库的部分有以下代码:

{/* COuntry */}
<View style={styles.container}>
<Text style={styles.titleText}>Select your country</Text>
<CountryPicker
disable={false}
animationType={"fade"}
containerStyle={styles.pickerStyle}
pickerTitleStyle={styles.pickerTitleStyle}
selectedCountryTextStyle={styles.selectedCountryTextStyle}
countryNameTextStyle={styles.countryNameTextStyle}
pickerTitle={"Select your country"}
searchBarPlaceHolder={"Search......"}
hideCountryFlag={false}
hideCountryCode={false}
searchBarStyle={styles.searchBarStyle}
countryCode={this.state.mCountryCode}
selectedValue={this._selectedValue}
/>
</View>

这是Vishal Dhanotiya的一个依赖项,您可以从以下网址找到代码:https://github.com/vishaldhanotiya/rn-country-picker/blob/master/index.js

它显示了第84行的错误。我只从组件中删除了道具,除此之外,我没有接触任何其他代码。它以前很好,但它突然抛出了这个错误。请帮忙。

是的,当然,它给出了异常,因为你像数组一样访问newData,它可能有一个布尔值。

const newData = CountryJSON.filter(function (item) {
const itemData = item.callingCode;
const textData = defaultText;
return itemData === textData; // it is returning boolean value here either true or false
});
return (
<View>
........
{hideCountryFlag ? null : (
<Image
source={{uri: newData[0].flag}} // It is an exception because it's either tru or false not array of course
style={styles.countryFlagContainer}
/>
)}
......
</View>
);

最新更新