我有一個數組包含JSON數組中的多個元素, 我可以通過做category.language
來訪問(JSON中還有其他幾個可訪問的元素例如做category.name
,category.photo
等)Angular2/Ionic - 查找數組中的重複項並對它們進行組織
English, Russian, French, Russian, English
我想要做的就是把重複的相互和最終達到有:
English, Russian, French
不去除DUPLIC ates,因爲刪除它們也會刪除其他相關元素,例如category.name
...,這些元素具有其他不同的值。
目前我獲取形式的REST API,下面是我的代碼:
Page.js
this.menuPages = {
pagination: '.swiper-pagination',
//need to have 1 or more (it should some how dynamic depending on the number of the unique items, i.e. sometimes should 1 slide per view, sometimes 10 slides per view)
slidesPerView: '1',
paginationClickable: true,
paginationBulletRender: function (index, className) {
console.log('print now2 : '+storeCategory[index]);
return '<span class="' + className + '">' + storeCategory[index] + '</span>';
}
}
page.html中
<ion-slides pager [options]="Pages">
<ion-slide *ngFor="#category of categories">
//put the duplicates with each other, to have one element or more in every slide(page)
<ion-row>
<ion-col>
<div class="title">{{category.name}</div>
<div class="subTitle"><br>{{category.photo}}</div>
</ion-col>
</ion-row>
</ion-slide>
</ion-slides>
我相信玩耍或者通過page.html
或者page.js
應該解決問題!我希望你能提出一些想法來解決它!