作者:壮丁1987_536 | 来源:互联网 | 2023-05-19 06:05
I have a Firebase database with this JSON:
我有一个JSON为基础的数据库:
"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...
I am using Angular 4 to output the Name
fields as headers and the individual items as list items:
我使用角4输出名称字段作为标题,单个项目作为列表项:
app.help-screen component.html
app.help-screen component.html
{{item.Name}}
- Potion Quantity: {{ item["Potion Quantity"] }}
- Price: {{ item.Price }}
- Stackable: {{ item.Stackable }}
- Quest Item: {{ item["Quest Item"] }}
- Max Stack: {{ item["Max Stack"] }}
app-help-screen.component.ts
app-help-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;
constructor(db: AngularFireDatabase) {
this.items = db.list('help_text');
console.log(this.items);
}
ngOnInit() {
}
}
This works but it's not very elegant and means the database code will have to be rewritten every time an object with a new property is added. What I would ideally like to do is output all fields as a list item, excluding the name, the model name and the mesh placement value. Looking at the Angularfire2 docs:
这是可行的,但并不十分优雅,这意味着每次添加新属性的对象时都必须重写数据库代码。我理想的做法是输出所有字段作为列表项,不包括名称、模型名称和网格放置值。看看Angularfire2文档:
https://github.com/angular/angularfire2/blob/master/docs/4-querying-lists.md
https://github.com/angular/angularfire2/blob/master/docs/4-querying-lists.md
there doesn't seem to be a way to exclude items from a query by key. Surely there must be a way to perform such a basic query using Firebase and Angularfire2?
似乎没有一种方法可以通过键将项从查询中排除。肯定有办法使用Firebase和Angularfire2执行这样的基本查询吗?
1 个解决方案