我對Angular 2比較新,我需要根據對象名的第一個字母對對象數組進行排序/分組。例如:Angular 2按對象排列組的第一個字母
{
"type": "fruit",
"name": "apple",
},
{
"type": "fruit",
"name": "banana",
},
{
"type": "vegetable",
"name": "broccoli",
},
{
"type": "fruit",
"name": "orange",
},
我想它表現出來,如:
<h3>A</h3>
<ul>
<li>apple</li>
</ul>
<h3>B</h3>
<ul>
<li>banana</li>
<li>broccoli</li>
</ul>
<h3>O</h3>
<ul>
<li>orange</li>
</ul>
我發現這個職位:How to group data in Angular 2 ?。
我試了一下,如:
<div *ngFor="let item of food | groupBy:'name.charAt(0)'">
<h3>{{name.charAt(0) | uppercase}}</h3>
<li>...</li>
</div>
我知道我可能需要一個管道,但我不能讓它的工作。
希望有人能幫助
@彼得,我也在尋找相同..請你讓我知道如何實現這一點? –