我有一个数组包含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
应该解决问题!我希望你能提出一些想法来解决它!