【发布时间】:2018-12-17 05:44:30
【问题描述】:
我在这里有一个嵌套数组,我在问题 300 下有一些答案。 这里有些答案也有回复。喜欢“parent_answer_id”
在我的应用程序中,我试图仅在 "parent_answer_id" == 0 显示在列表中并且如果其他项目的 "parent_answer_id" 与其他项目匹配 "id" 然后将在该循环上显示额外的内容 "more reply >"。
到目前为止,我尝试过 react native:
var k =0;
for ( let j = 0; j < Object.keys(item.answers[1]).length; j++) {
if (item.answers[1][j].parent_answer_id==0) {
var parent = 1;
};
if (parent) {
k++;
if (count-1 == j) {
var last = 1;
}
parents.push(
<View key={j}>
<View style={styles.answerItem}>
<View >
<Text>
{item.answers[1][j].content}
</Text>
</View>
<View>
<Text>more reply > </Text>
</View>
</View>
</View>
);
};
}
我的示例数组在这里
"answers": [
[ 5,
{
"id": "215",
"parent_answer_id": "214",
"question_id": "300",
"content": "zksjbviul",
"question_content": "gggg",
"is_like": "0",
},
{
"id": "214",
"parent_answer_id": "213",
"question_id": "300",
"content": "ksdgzbvjzh,",
"question_content": "gggg",
},
{
"id": "213",
"parent_answer_id": "0",
"question_id": "300",
"content": "kuqebvjzd",
"question_content": "gggg",
},
{
"id": "212",
"parent_answer_id": "0",
"question_id": "300",
"content": "iauvhiuds",
"question_content": "gggg",
},
{
"id": "211",
"parent_answer_id": "0",
"question_id": "300",
"content": "fdfs",
"question_content": "gggg",
},
]
],
【问题讨论】:
标签: javascript arrays json reactjs react-native