2017-05-29 110 views
1

我正在使用ionic 3和Baqend爲BaaS構建一個應用程序。使用Baqend檢索嵌套數據 - undefined

如果我有以下數據:

product :{ 
    id: xxx, 
    item: { 
     name: "Name", 
     description: "product details.." 
    } 
} 

如何檢索 'item.name' 的價值?

我試過以下,但給我'未定義'。它適用於如果我做product.id但不是嵌套數據的情況。

import { baqend } from "baqend"; 

... 

db: baqend; 

... 

this.db.Products.find().resultList(function(results) { 
    results.forEach(function(product) { 
     console.log(product.item.name); 
    }); 
}); 

我下面的Baqend指南: https://www.baqend.com/guide/topics/queries/

回答

1

在出現這種情況,如果你沒有在架構中定義的項目和名稱屬性正確大多數情況下。 要將數據實際嵌套在baqend模型中,您應該將該屬性定義爲embedded property(如下面的屏幕截圖所示)或作爲無類型的JsonObject。

你定義產品的架構應該類似於以下內容:

Products schema

希望,到目前爲止幫助。

+0

我明白了。我實際上是使用類型'列表'的項目。我需要首先在什麼地方聲明'ProductItem'嗎? –

+2

我明白了,謝謝。我已經標記了你的答案。 –