@Angular/Fire操纵响应可观察到

发布于 2025-02-04 20:13:48 字数 1919 浏览 4 评论 0原文

我使用实时数据库在兼容模式下使用 @Angular/Fire 9。当我将可观察的服务从我的服务中返回到控制器中时,这很好,但我很难操纵返回的数据。

例如,我的服务需要从表格中获取所有记录,并在每个记录上执行一些数学。要获取直截了当的列表,然后使用Angular Controller中的Async()管道,我使用一种服务方法:

public GetTransactionDetails(TransactionNo: string): Observable<Array<TransactionItemDetails>> {
    const Location: string = `TransDetail/${TransactionNo}`;
    const ItemListing$ = this.AngularFireDB_.list<TransactionItemDetails>(Location, ref => ref.orderByChild('item_code')).valueChanges();
    return ItemListing$;
}

This Jung in @angular/fire中的表格中的所有信息都可以获取我的详细信息列表。但是,我不是存储总价,并希望通过乘以数量 *单位价格来计算这一点。在这种情况下,我似乎无法获得地图功能。

public GetTransactionDetails(TransactionNo: string): Observable<Array<TransItemDetail>> {
    const Location: string = `TransDetail/${TransactionNo}`;
    const ItemListing$ = this.AngularFireDB_.list<TransItemDetail>(Location, ref => ref.orderByChild('item_code')).valueChanges().pipe( map(AllItems: Array<TransItemDetail>) => {
        // My understanding is this is all the data, so I need to loop again through this.
        AllItems.map( (OneItem: TransItemDetail) => {
            OneItem.ItemTotal = OneItem.Quantity * OneItem.UnitPrice;
        });
    });
    return ItemListing$;
}

但是,我会以这种格式获得编译错误。

Type 'Observable<void>' is not assignable to type 'Observable<TransItemDetail[]>'.

键入“ void”不可分配给'transitemdetail []''。ts(2322)

如果然后将定义添加到管道中,则错误会更改为:

pipe<Array<TransItemDetail>>( map(AllItems: Array<TransItemDetail>) => {

Argument of type 'OperatorFunction<TransItemDetail[], void>' is not assignable to parameter of type 'OperatorFunction<TransItemDetail[], TransItemDetail[]>'.
  Type 'void' is not assignable to type 'TransItemDetail[]'.ts(2345)

我不知道如何将其移动以获得我的结果。

I am working with @angular/fire 9 in compatibility mode using the real time database. While I am returning the observable from my service into my controller, and this works fine, I am having trouble manipulating data being returned.

For instance, my service needs to get all the records from a table, and perform some math on each record. To get the straight forward list, then use the async() pipe in my Angular controller, I use a service method like:

public GetTransactionDetails(TransactionNo: string): Observable<Array<TransactionItemDetails>> {
    const Location: string = `TransDetail/${TransactionNo}`;
    const ItemListing$ = this.AngularFireDB_.list<TransactionItemDetails>(Location, ref => ref.orderByChild('item_code')).valueChanges();
    return ItemListing$;
}

This works to get my list of detail, with all the information I have in the table in @angular/fire. However, I am not storing the Total Price, and want to calculate that by multiplying the Quantity * Unit Price. I cannot seem to get a map function to work in this case.

public GetTransactionDetails(TransactionNo: string): Observable<Array<TransItemDetail>> {
    const Location: string = `TransDetail/${TransactionNo}`;
    const ItemListing$ = this.AngularFireDB_.list<TransItemDetail>(Location, ref => ref.orderByChild('item_code')).valueChanges().pipe( map(AllItems: Array<TransItemDetail>) => {
        // My understanding is this is all the data, so I need to loop again through this.
        AllItems.map( (OneItem: TransItemDetail) => {
            OneItem.ItemTotal = OneItem.Quantity * OneItem.UnitPrice;
        });
    });
    return ItemListing$;
}

However, I get compile errors in this format.

Type 'Observable<void>' is not assignable to type 'Observable<TransItemDetail[]>'.

Type 'void' is not assignable to type 'TransItemDetail[]'.ts(2322)

If I then add the definition to the pipe, the error changes to:

pipe<Array<TransItemDetail>>( map(AllItems: Array<TransItemDetail>) => {

Argument of type 'OperatorFunction<TransItemDetail[], void>' is not assignable to parameter of type 'OperatorFunction<TransItemDetail[], TransItemDetail[]>'.
  Type 'void' is not assignable to type 'TransItemDetail[]'.ts(2345)

I do not know how to move past this to get my results.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文