0
你好我想只顯示包括wishlist數組中的用戶標識的數據。我做錯了什麼?通過ID過濾數據
items = { "_id" : ObjectId("58016d54c6622964cc8906be"), "wishlist":[5893278927277749594, 5893278927277749595, 5893278927277749596] "country" : "Ireland" }
管道文件
import {Pipe} from 'angular2/core';
@Pipe({
name: 'WishListFilter'
})
export class WishListPipe {
transform(items, args?): any {
return items.filter(items => items.wishlist == args.userId);
}
}
組件文件
import { WishListPipe } from './wishlist-pipe';
@Component({
selector: 'wislist',
pipes: [ WishListPipe ],
template: `
<ul>
<li *ngFor="let item of (items | WishListFilter:this.userId">{{item}}</li>
</ul>
`
})
export class MainSite(){
public userId = '5893278927277749595'
}