我从fetch.php
文件中以离子形式从HTTP源中获取数据:
$mysqli =mysqli_connect("test.com", "test", "test@123", "test");
mysqli_set_charset($mysqli,"utf8");
$query = "SELECT * FROM store";
$dbresult = $mysqli->query($query);
while($row = $dbresult->fetch_array(MYSQLI_ASSOC)){
$data[] = array(
'sto_gender_id' => $row['sto_gender_id'],
'sto_category_id' => $row['sto_category_id'],
);
}
if($dbresult){
$result = json_encode($data);
}
else {
$result = "{'success':false}";
}
echo $result;
我通过此提供者category.ts
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
@Injectable()
export class CategoryProvider {
constructor(public http: HttpClient) {
console.log('Hello CategoryProvider Provider');
}
getCategory(){
return this.http.get<any[]>('https://www.test.com/test/fetch.php')
}
}
我通过此html文件显示结果:
<button ion-button block *ngFor="let category of allCategory" (click)="goToGenderPage(category)">
{{category.sto_category_id}}{{category.sto_gender_id}}
</button>
但是问题是它显示具有相同sto_category_id
[{"sto_gender_id":"1","sto_category_id":"1"},
{"sto_gender_id":"2","sto_category_id":"1"},
{"sto_gender_id":"1","sto_category_id":"4"},
{"sto_gender_id":"2","sto_category_id":"2"}]
,但我不希望这样做,因此有任何方法可以基于sto_category_id
过滤结果,以仅显示多个中的一个sto_category_id
。喜欢:
[{"sto_gender_id":"1","sto_category_id":"1"},
{"sto_gender_id":"1","sto_category_id":"4"},
{"sto_gender_id":"2","sto_category_id":"2"}]
那么最好的方法是什么。