Javascript 结果为零的Reactjs过滤器
我希望在没有显示映射数组中的项目时更改页面上的文本。 我正在显示一个问题列表,但如果一个问题是“已回答”(回答:true的布尔值),则它不会被映射 我试图找出确定数组中的每个项是否都已回答:true的最佳方法,然后相应地更改页面上的文本。当我需要一个函数来检查是否没有结果返回时,是否可以使用过滤器 页面左侧显示列表,右侧显示文本“请单击问题”。选择问题时,它会将“请单击问题”替换为有关所选问题的信息。但当没有问题时,我希望“请点击一个问题”显示类似“目前没有问题要回答”的内容Javascript 结果为零的Reactjs过滤器,javascript,reactjs,filter,mapping,Javascript,Reactjs,Filter,Mapping,我希望在没有显示映射数组中的项目时更改页面上的文本。 我正在显示一个问题列表,但如果一个问题是“已回答”(回答:true的布尔值),则它不会被映射 我试图找出确定数组中的每个项是否都已回答:true的最佳方法,然后相应地更改页面上的文本。当我需要一个函数来检查是否没有结果返回时,是否可以使用过滤器 页面左侧显示列表,右侧显示文本“请单击问题”。选择问题时,它会将“请单击问题”替换为有关所选问题的信息。但当没有问题时,我希望“请点击一个问题”显示类似“目前没有问题要回答”的内容 this.stat
this.state={
问题:[],
当前问题:空,
当前索引:-1,
查询问题:“,
删除:false
};
{问题&&
问题.地图((问题,索引)=>(
{!问题。回答&&
this.setActiveQuestion(问题,索引)}
键={index}
>
{问题.问题}
}
))}
{你的问题是什么(
问题:
{" "}
{currentQuestion.question}
类别:
{" "}
{currentQuestion.categoryId}
状态:
{" "}
{currentQuestion.answered?“已回答”:“等待回答”}
回答这个问题
) : (
请点击一个问题
)}
);
}
}
const nothingToAnswer=questions.every(question=>question.responsed)代码>const nothingToAnswer=questions.every(question=>question.responsed)代码>是你的朋友是你的朋友非常感谢!我觉得过滤器不是最好的功能。这正是我所需要的,我会把你分享的页面加入书签,非常感谢!我觉得过滤器不是最好的功能。这正是我所需要的,我会把你分享的页面加入书签,谢谢
this.state = {
questions: [],
currentQuestion: null,
currentIndex: -1,
searchQuestion: "",
wanttodelete: false
};
{questions &&
questions.map((question, index) => (
<div key={index}>
{!question.answered &&
<li
className={
"list-group-item " +
(index === currentIndex ? "active" : "")
}
onClick={() => this.setActiveQuestion(question, index)}
key={index}
>
<p>
{question.question}
</p>
</li>
}
</div>
))}
</ul>
</div>
<div className="col-lg-8 question-area">
{currentQuestion ? (
<div>
<h4>
<FormattedMessage
id="question-list.questionHeader"
defaultMessage="Question"
description="Question header"/>
</h4>
<div>
<label>
<strong>Question:</strong>
</label>{" "}
{currentQuestion.question}
</div>
<div>
<label>
<strong>Category:</strong>
</label>{" "}
{currentQuestion.categoryId}
</div>
<div>
<label>
<strong>Status:</strong>
</label>{" "}
{currentQuestion.answered ? "Answered" : "Awaiting answer"}
</div>
<Link
to={"/questions/" + currentQuestion.id}
className="badge badge-warning"
>
Answer this question
</Link>
</div>
) : (
<div>
<p>Please click on a Question...</p>
</div>
)}
</div>
</div>
</div>
</div>
);
}
}