简体   繁体   English

多个navigation.push同一个屏幕总是go到列表的最后

[英]Multiple navigation.push same screen always go to the last of the list

I have a screen to display news articles.我有一个屏幕来显示新闻文章。 In a news there can be reference to other articles.在新闻中可以参考其他文章。 On clicking on the reference i go to another news detail screen which display the new articles.单击参考 go 到另一个显示新文章的新闻详细信息屏幕。 If have only one reference to another article, it works fine, even go back.如果只有一个参考另一篇文章,它工作正常,甚至 go 回来。 But if i have more reference, i always go to the last news article and not to the specific news article i am clicking on.但如果我有更多参考,我总是 go 到最后一篇新闻文章,而不是我点击的具体新闻文章。 The reference is the "id" of the article, pass via the param of a navigation.push, inside a.引用是文章的“id”,通过navigation.push 的参数传递,在a 中。 Why is it always the last news id that is used?为什么总是使用最后一个新闻 ID? I put the id (infNum) in the area, and it references the correct id of each article, but it seems that the param idNews is always the last infNum.我把id(infNum)放在了area里面,它引用了每篇文章的正确id,但是好像参数idNews总是最后一个infNum。 Here is my code: '''这是我的代码:'''

{news.results.texte.map((content, index) => {
        if(content.substring(0,6) === '_Info_') {
            {
            finNum = content.indexOf("_T_");
            finLien = content.indexOf("_/Info_");
            infNum = content.substring(6,finNum);
            txtLien = content.substring(finNum+3,finLien)
            }
            //console.log(finNum," ",finLien," ",infNum," ",txtLien)
            return (
                <TouchableOpacity
                    style={styles.txtLien}
                    key={infNum}
                    onPress={() => {
                        navigation.push("NewsDetail", {idNews:infNum})}
                    }
                >
                    <Text>{txtLien}-{infNum}</Text>
                </TouchableOpacity>
            )
        } else {
            return (
              <Text style={styles.description_text} key={index}>{content}</Text>
            )
        }

''' '''

I found the problem.我发现了问题。 Basic Javascript.基本 Javascript。 The variable 'infNum' as it is not declared with the 'var' keyword is considered as global and so takes the last value given.未使用 'var' 关键字声明的变量 'infNum' 被视为全局变量,因此采用最后给出的值。 I just put 'var infNum = content.substring....' and it works well我只是放了'var infNum = content.substring ....',效果很好

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 navigation.push 上的 clearInterval() 反应 - clearInterval() on navigation.push react 如何使用 react-native-navigation 在 Navigation.push 上将视图从 Tab 更改为 Screen - How can I change my view from Tab to Screen on Navigation.push with react-native-navigation navigation.push不添加新路由 - navigation.push not adding a new route navigation.push('SearchPage', {search_params: item.school_type}); naviagtion.push 不改变屏幕 - navigation.push('SearchPage', {search_params: item.school_type}); naviagtion.push does not changing screen 对于 react-native 中抽屉导航的 contentComponent,navigation.push 中未定义 - navigation.push in undefined for contentComponent of drawer navigation in react-native 如果我 go 逐页返回,navigation.navigate()、navigation.push()、navigation.goBack() 和 navigation.popToTop() 有什么区别? - What is a difference between navigation.navigate(), navigation.push(), navigation.goBack() and navigation.popToTop() if I go back from page to page? React Native Error undefined 不是一个对象(评估“navigation.push”) - React Native Error undefined is not an object (evaluating 'navigation.push') TypeError: undefined is not an object (evalating 'navigation.push') React Native - TypeError: undefined is not an object (evaluating 'navigation.push') React Native 如何修复 undefined 不是 object(评估“navigation.push”) - How to fix undefined is not an object (evaluating 'navigation.push') React native navigation.push 没有从参数更新 UI - React native navigation.push is not updating the UI from the params
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM