我正在使用react-native firebase 将我的媒体保存到firebase 中。我有一组需要保存在 firebase 中的 URL。为此,我使用 map() 来一一保存。保存后,我将成功 URL 推送到数组中。我需要用这个数组作为参数来调用一个函数。所以我需要在数组完成后调用这个函数。我进行了很多搜索,但没有找到此任务的良好解释。谁能帮我。谢谢。
var mediaArray = []; //array of success callbacks values
var completedMediaSurveysAnswers = [{}, {}, {}]; //object array of URLs and media types
completedMediaSurveysAnswers.map((i) => {
try {
const storage = firebase.storage();
const mRef = storage.ref('portal').child('Survey/Image/user/' + uuidv4() + 'media');
mRef.putFile(i.urlPath, {
contentType: i.mediaType
})
.on('state_changed', snapshot => {},
err => {
console.log('Failed to upload file to firebase storage')
},
uploadedFile => {
// Success
this.setState({
mediaPath: uploadedFile.downloadURL
})
mediaArray.push(this.state.mediaPath) …Run Code Online (Sandbox Code Playgroud) 当我的部分为空时,我试图渲染空组件。这是我的示例代码
<SectionList
sections={[
{title: 'sectionOne', data: this.props.Activities.ActivityTypeOne},
{title: 'sectionTwo', data: this.props.Activities.ActivityTypeTwo},
{title: 'sectionThree', data: this.props.Activities.ActivityTypeThree}
]}
keyExtractor={ (item, index) => index }
stickySectionHeadersEnabled={true}
extraData={this.state}
ListEmptyComponent={this.renderEmptyScreens}
/>
Run Code Online (Sandbox Code Playgroud)
但是当这 3 个所有数组都为空时,它不会触发ListEmptyComponent
任何人都可以告诉我这段代码有什么问题,或者如果我的逻辑不正确,任何人都可以解释一下。基本上我需要在所有 3 个数组都为空时呈现一些视图。