2
我有一個火力地堡數據庫與此JSON:排除關鍵項目與Angularfire2
"help_text": [{
"Name": "Blue Dye",
"Max Stack": 5,
"Potion Quantity": 1,
"Price": 10,
"Stackable": true
},
{
"Name": "Blue Gem",
"Max Stack": 20,
"Price": 200,
"Quest Item": true,
"Stackable": true
},
{
"Name": "Blue Gem Fragment",
"Max Stack": 20,
"Price": 50,
"Quest Item": true,
"Stackable": true
},
{
"Name": "Blue Flower",
"Max Stack": 20,
"Mesh Y": -0,
"Model": "blue_flower",
"Price": 5,
"Stackable": true
}
...etc etc...
我使用角4輸出Name
字段標題和個別項目列表項:
app.help屏幕component.html
<div class="help-item-box" *ngFor="let item of items | async">
<h2 class="help-item-title">{{item.Name}}</h2>
<ul class="help-item-properties">
<li *ngIf="item['Potion Quantity']">Potion Quantity: {{ item["Potion Quantity"] }}</li>
<li *ngIf="item.Price">Price: {{ item.Price }}</li>
<li *ngIf="item.Stackable">Stackable: {{ item.Stackable }}</li>
<li *ngIf="item['Quest Item']">Quest Item: {{ item["Quest Item"] }}</li>
<li *ngIf="item['Max Stack']">Max Stack: {{ item["Max Stack"] }}</li>
</ul>
</div>
應用程序的幫助,screen.component.ts
import { Component, OnInit } from '@angular/core';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
@Component({
selector: 'app-help-screen',
templateUrl: './app-help-screen.component.html',
styleUrls: ['./app-help-screen.component.css']
})
export class HelpScreenComponent implements OnInit {
items: FirebaseListObservable<any[]>;
constructor(db: AngularFireDatabase) {
this.items = db.list('help_text');
console.log(this.items);
}
ngOnInit() {
}
}
這工作,但它不是很優雅,意味着數據庫的代碼將在每次添加一個新的屬性對象時被重寫。理想情況下,我想將所有字段輸出爲列表項,不包括名稱,型號名稱和網格佈局值。縱觀Angularfire2文檔:
https://github.com/angular/angularfire2/blob/master/docs/4-querying-lists.md
似乎沒有要通過關鍵排除查詢項目的方式。當然,必須有方法使用Firebase和Angularfire2來執行這樣的基本查詢?
加一個if?過濾一組Object.keys? –
我誤解你的意思排除? –
儘管事實準確,但這是一個糟糕的答案。關於工作狀態,我不得不接受這封信。 –