๋๋ถ๋ฅ ์นดํ ๊ณ ๋ฆฌ ๋ง๋ค๊ธฐ
categoryList ๋ณ์์์ 2์ค ๋ฐฐ์ด์ ๋ง๋ ๋ค.
categoryList = [
{
category : 'IT',
children : [
{name: '๊ธฐํ'},
{name: '๋์์ธ'},
{name: '๊ฐ๋ฐ'},
{name: '๋ฐ์ดํฐ์ฌ์ด์ธ์ค'},
{name: '๋ง์ผํ
'},
],
},
{
category : '์ดํ',
children : [
{name: 'ํํ'},
{name: '์๋ฌธ'},
{name: '์๊ฒฉ์ฆ'},
{name: '์ธ์ด๊ตํ'},
],
},
]
for๋ฌธ์ ๋๋ฆด ์์น์ ๋ฐฐ์ด์ ๋ง๋ categoryList ๋ฅผ categorylistbig ์ผ๋ก ๋ฐ์์
๋๋ถ๋ฅ์ธ category์ ์ ๊ทผ
<ul class="reed-menu-list">
<li class="reed-menu-item"
*ngFor="let categorylistbig of categoryList"
(click)="categoryBigMenu(categorylistbig)">
<button>{{categorylistbig.category}}</button>
</li>
</ul>
์ด๋ ํด๋ฆญ์ด๋ฒคํธ๋ฅผ ๊ฑธ์ด ํด๋ฆญ์ ํด๋น ๋ฐ์ดํฐ๋ฅผ ๋ฐ๊ฒ๋ ๋งค๊ฐ๋ณ์๋ฅผ ๋ฃ์ด์ค
ํด๋ฆญ์ categoryBigMenu ํจ์ ์คํ > categorylistbig > ๋๋ถ๋ฅ ์นดํ ๊ณ ๋ฆฌ ํญ๋ชฉ์ ๋ฐ์
categoryBigMenu(selectedCategoryInfo){
console.log('selectedCategoryInfo: ', selectedCategoryInfo);
console.log(selectedCategoryInfo.children)
categoryBigMenu(selectedCategoryInfo) ์ ๋ฐ์ดํฐ ๋ด์ฉ์
๋๋ถ๋ฅ IT ์ ๋ํ children ์ด ๋ค์ด์จ๋ค.
์ ๋ณด๊ฐ ์๋ ํจ์์์ chiledren์ ๋ฐ์์ค๊ธฐ ์ํด์ ๋ฆฌ์คํธ ๋ณ์๋ฅผ ํ๋ ๋ ๋ง๋ค์ด์ค๋ค.
๋๋ถ๋ฅ ํญ๋ชฉ๋ค์ ๋ฐ์ ๋น ๋ฐฐ์ด ๋ณ์
categorySmall = []
//์ ํ๋ ์์ ์นดํ
๊ณ ๋ฆฌ๋ฅผ ๋ฐ์ ๋น๋ฐฐ์ด ๋ณ์๋ฅผ ๋ง๋ฆ
categorySmall = []
๋ง๋ ๋น๋ฐฐ์ด ๋ณ์์ ํด๋ฆญ๋ ๋๋ถ๋ฅ์ children ์ ๋ด๋๋ค.
categoryBigMenu(selectedCategoryInfo){
console.log('selectedCategoryInfo: ', selectedCategoryInfo);
this.categorySmall = selectedCategoryInfo.children
console.log('categorySmall: ', this.categorySmall);
}
์ฆ ๋น๋ฐฐ์ด์ด ์๋ caregorySmall ์ ๋๋ถ๋ฅ ํด๋ฆญ์ ๋ฐ์ ๋ฐ์ดํฐ selectedCategoryInfo์ children ์ ๋ด๋๋ค.
๋ง์ง๋ง html ์์ for ๋ฌธ ๋๋ฆฌ๊ธฐ
<ul class="reed-menu-list">
<li class="reed-menu-item" *ngFor="let categorylistsmall of categorySmall"
(click)="categoryBigMenu(categorySmall)">
<button>{{categorylistsmall.name}}</button>
</li>
</ul>
*ngFor="let categorylistsmall of categorySmall"
ํด๋ฆญ์ด๋ฒคํธ๋ก categoryBigMenu ํด๋ฆญ์ ๋น๋ฐฐ์ด์ ๋ด์๋์ categorySmall ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ด
(click)="categoryBigMenu(categorySmall)">
๊ฐ์ ธ์จ ํ์ ์นดํ ๊ณ ๋ฆฌ ๋ฐ์ดํฐ์์ name ์์ ๊ทผ
{{categorylistsmall.name}}
์๋ฐ์คํฌ๋ฆฝํธ ์ ์ฒด (์ต๊ทค๋ฌ)
categorySmall = []
categoryList = [
{
category : 'IT',
children : [
{name: '๊ธฐํ'},
{name: '๋์์ธ'},
{name: '๊ฐ๋ฐ'},
{name: '๋ฐ์ดํฐ์ฌ์ด์ธ์ค'},
{name: '๋ง์ผํ
'},
],
},
{
category : '์ดํ',
children : [
{name: 'ํํ'},
{name: '์๋ฌธ'},
{name: '์๊ฒฉ์ฆ'},
{name: '์ธ์ด๊ตํ'},
],
},
]
categoryBigMenu(selectedCategoryInfo){
console.log('selectedCategoryInfo: ', selectedCategoryInfo);
this.categorySmall = selectedCategoryInfo.children
console.log('categorySmall: ', this.categorySmall);
}
'javascript๐ช > ์๋ฐ์คํฌ๋ฆฝํธ ๊ณต๋ถ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์ต๊ทค๋ฌ ์ด๋ฒคํธ ์ ํ ๋ง๊ธฐ (1) | 2023.11.22 |
---|---|
Animate.css ํ์ฉ fadeInํจ๊ณผ ๊ฑธ๊ธฐ (0) | 2023.10.23 |
์๋ฐ์คํฌ๋ฆฝํธ๋ก ์ฌ๋ผ์ด๋ ์ธ๋์ผ์ดํฐ indicator ๊ตฌํํ๊ธฐ (active or forEach) (0) | 2023.10.23 |
์๋ฐ์คํฌ๋ฆฝํธ๋ก ์๋ ์ฌ๋ผ์ด๋ ๊ตฌํํ๊ธฐ (querySelector / setInterval) (1) | 2023.10.18 |
function ์ด๋? (0) | 2023.09.05 |
๋๊ธ