【发布时间】:2021-03-30 11:35:58
【问题描述】:
我正在尝试折叠和展开。所以当用户点击“Section Title”时,它会折叠相应的信息。
@Component({
selector: 'knowledge-base',
template: `
<div *ngFor="let section of questions">
<h2>{{section.sectionTitle}}</h2>
<div class="submenu">
<div *ngFor="let q of section.questions">
<div class="questions"> <span class="question">Q.</span> {{q.question}}<br/></div>
<div class="answers"> <span class="answer">A.</span> {{q.answer}}<br/></div>
<div *ngIf="q.issues?.length">
<span>Issues:</span>
<div class="issues" *ngFor="let issue of q.issues">{{issue}}<br/></div>
</div>
</div>
</div>
<hr>
</div>
`,
styles: [`
h2 {
margin-left: 15px;
margin-bottom: 20px;
margin-top: 25px;
}
hr {
width: 90%;
margin: 0px auto;
}
.submenu {
margin-left: 15px;
}
.questions {
font-weight: bold;
margin-left: 15px;
}
.answers {
font-weight: italic;
font-style: italic;
margin-top: 15px;
margin-left: 15px; margin-bottom: 20px;
}
.issues {
float: left;
color: red;
width: 100%;
margin-top: 15px;
margin-bottom: 15px;
}
.question {
font-weight: bold;
}
.answer{
font-weight: bold;
}
` ],
})
export class KnowledgeBaseComponent {
questions = knowledgeData()
}
这是我要折叠和展开的数据。我尝试在带有 css 的部分标题周围使用 div,但似乎不起作用
export const knowledgeData = (): KnowledgeDataModel[] => [
{
sectionTitle:'Mission and Vision Statements',
questions: [
{
question: 'What is our short term mission and our long term vision',
answer: `With the current advancement in the medical field, it means that we can live longer than
ever before, however, it comes with its issues.`,
issues: [],
},
],
},
{
sectionTitle:'Account Management',
questions: [
{
question: 'What are accounts and how do I make one?',
answer: 'Accounts group together users, there are provider accounts for agents and consumer
accounts for users',
issues: [
'currently unable to rename an account',
'currently unable to delete an account once users have been added',
],
}
]
我想在用户点击“Section Title”时展开,在点击“Section Title”时折叠?
谢谢
【问题讨论】:
-
你想隐藏“子菜单”?
标签: javascript angular