它有效,但我得到的结果应该排序。无论我在搜索栏中输入什么,我都会得到相同的结果
我希望它像自动完成一样排序。显示我在搜索栏中输入内容的结果
search.ts
@Component({ selector: "page-search", templateUrl: "search.html" })
export class SearchPage {
filter: string = '';
public userDetails: any;
public resposeData: any;
public dataSet: any;
public userSet: any;
public mediaSet: any;
public noRecords: boolean;
userPostData = {
uid: "",
token: "",
username: "",
bio: ""
};
constructor(
public common: Common,
public navCtrl: NavController,
public app: App,
public menu: MenuController,
public authService: AuthService,
public http: Http,
platform: Platform,
statusBar: StatusBar,
splashScreen: SplashScreen
) {
this.initializeItems();
this.mostmediaList();
}
initializeItems() {
return this.userPostData;
}
getItems(ev: any) {
this.initializeItems();
let val = ev.target.value;
if (val && val.trim() != '') {
this.authService.postData(this.userPostData, "userGroupSearch").then(
result => {
this.resposeData = result;
if (this.resposeData.allArtistsData) {
this.userSet = this.resposeData.allArtistsData;
console.log(this.userSet);
} else {
console.log("No access");
}
},
);
}
}
答案 0 :(得分:0)
由于您的代码已包含在
中if (this.resposeData.items) {
//some code
}
我们确定this.resposeData
不是一个数组,因为它有一个items
成员(否则你if
内的代码就不会被执行,因此你不会得到一个我们有的错误。
因为您在
处调用参数items
this.userSet = this.resposeData.filter((items) => {
//some code
};
可以安全地假设您想要filter
this.resposeData.items
而不是this.resposeData
。因此,您需要确保它是if
if (this.resposeData.items && Array.isArray(this.resposeData.items)) {
//some code
}
和filter
this.resposeData.items
代替this.resposeData
:
this.userSet = this.resposeData.items.filter((items) => {
//some code
};