1
以我離子應用數據,我已經在我的home.ts以下:使用離子搜索欄通過http.get來過濾離子
export class HomePage {
itemsInitial = []; //initialize your itemsInitial array empty
items = []; //initialize your items array empty
gameTitlesInitial = []; //initialize your itemsInitial array empty
gameTitles = []; //initialize your items array empty
searchGameTitleString = ''; // initialize your searchItemsString string empty
constructor(http: Http) {
http.get('http://localhost/wordpress-templates/wordpress/index.php/wp-json/wp/v2/business/')
.map(res => res.json())
.subscribe(data => {
this.itemsInitial = data;
this.items = data;
var gameTitles = this.items.map(function (el) {
return el.title.rendered;
});
console.log(gameTitles);
});
}
searchGameTitle(searchbar) {
// reset items list with initial call
this.gameTitles = this.gameTitlesInitial;
// set q to the value of the searchbar
var q = searchbar.target.value;
// if the value is an empty string don't filter the items
if (q.trim() == '') {
return;
}
this.gameTitles = this.gameTitles.filter((v) => {
if (v.toLowerCase().indexOf(q.toLowerCase()) > -1) {
return true;
}
return false;
})
}
}
....和我home.html的以下內容:
<ion-content>
<ion-searchbar [(ngModel)]="searchGameTitleString" (input)="searchGameTitle($event)" placeholder="Search"></ion-searchbar>
<ion-list>
<button ion-item *ngFor="let gameTitle of gameTitles">
{{gameTitle}}
</button>
</ion-list>
</ion-content>
有人可以幫助我:我怎樣才能更換空陣「gameTitles」在使用var在我的HTTP「gameTitles」得到的值頂部?
console.log(gameTitles);
確實給我
["game one", "game two", "game three"]
在控制檯
...這樣的HTTP GET似乎工作。
我非常感謝任何幫助 - 我嘗試了很多方法,但沒有取得任何成功。