[英]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.